0
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']
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
tbysyl
  • 1
  • 2
    Does this answer your question? [How to split a string into a list?](https://stackoverflow.com/questions/743806/how-to-split-a-string-into-a-list) – Wups Oct 11 '20 at 15:17
  • as MyList is a list of string containing one string, you should be able to call .split on that string via MyList = MyList[0].split(',') – Abel Oct 11 '20 at 15:18

3 Answers3

3

Split the first element.

MyList = ['a,b,c,d,e']
MyList = MyList[0].split(',')

Out:

['a', 'b', 'c', 'd', 'e']
Equinox
  • 6,483
  • 3
  • 23
  • 32
  • 1
    @ybot Consider accepting his answer, if it worked for you, by clicking the grey / green tick below the arrow of the answer. – solid.py Oct 11 '20 at 15:24
2

Use the split method on the string

MyList = MyList[0].split(',')
sspathare97
  • 333
  • 2
  • 12
0

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']
balderman
  • 22,927
  • 7
  • 34
  • 52