user63040
0
Q:

python split string into list

# Python3 program to Split string into characters 
def split(word): 
    return [char for char in word]  
      
# Driver code 
word = 'geeks'
print(split(word)) 
1
string = 'this is a python string'
wordList = string.split(' ')
5
>>> txt = "hello, my name is Peter, I am 26 years old"

>>> x = txt.split(", ")

>>> print(x)
["hello", "my name is Peter", "I am 26 years old"]
3
txt = "welcome to the jungle"

x = txt.split()

print(x)
5
sentence = 'This is a sentence'
split_value = []
tmp = ''
for c in sentence:
    if c == ' ':
        split_value.append(tmp)
        tmp = ''
    else:
        tmp += c
if tmp:
    split_value.append(tmp)
0

New to Communities?

Join the community