Answers for "can we convert string to list in python"

44

convert string to list python

# To split the string at every character use the list() function
word = 'abc'
L = list(word)
L
# Output:
# ['a', 'b', 'c']

# To split the string at a specific character use the split() function
word = 'a,b,c'
L = word.split(',')
L
# Output:
# ['a', 'b', 'c']
Posted by: Guest on February-18-2020
0

string to list

>>> names='''
...       Apple
...       Ball
...       Cat'''
>>> names
'n      Applen      Balln      Cat'
>>> names_list = [y for y in (x.strip() for x in names.splitlines()) if y]
>>> # if x.strip() is used to remove empty lines
>>> names_list
['Apple', 'Ball', 'Cat']
Posted by: Guest on December-15-2021

Code answers related to "can we convert string to list in python"

Python Answers by Framework

Browse Popular Code Answers by Language