python print string to list code example

Example 1: how to convert a string to a list python

#How to split a string into a list (Python)

#"separator" should be replaced with the string you want to split with
string.split("separator")

Example 2: print string elements in list python

# list having all elements are strings
strings = ['string1', 'string2', 'string3', 'string4']
for string in strings:
    print(string)

Example 3: python3 create list from string

input = ['word1, 23, 12','word2, 10, 19','word3, 11, 15']
output = []
for item in input:
    items = item.split(',')
    output.append([items[0], int(items[1]), int(items[2])])

Tags:

Java Example