Reputation: 1
MyList = ['a,b,c,d,e']
Is there any way to split a list (MyList
) with a single item, 'a,b,c,d,e'
, at each comma so I end up with:
MyList = ['a','b','c','d','e']
Upvotes: 0
Views: 393
Reputation: 23825
See below
lst_1 = ['a,b,c,d,e']
lst_2 = [x for x in lst_1[0] if x != ',']
print(lst_2)
output
['a', 'b', 'c', 'd', 'e']
Upvotes: 0
Reputation: 343
Use the split
method on the string
MyList = MyList[0].split(',')
Upvotes: 2
Reputation: 6758
Split the first element.
MyList = ['a,b,c,d,e']
MyList = MyList[0].split(',')
Out:
['a', 'b', 'c', 'd', 'e']
Upvotes: 3