-2

I am trying to convert a long string to a list of strings for each item separated with comma.

list = ['05-19.scl, 05-22.scl, 05-24.scl, 06-41.scl']

to :

desired_list= ['05-19.scl', '05-22.scl', '05-24.scl', '06-41.scl']
3
  • 3
    This is very basic if you don't mind me saying. But desired_list = list[0].split(", ") Commented Oct 8, 2020 at 7:28
  • 2
    Does this answer your question? How to convert comma-delimited string to list in Python? Commented Oct 8, 2020 at 7:32
  • Thanks you all. yes after another 5 min of searching I found the answer on google. Sorry - Will look a little deeper next time Commented Oct 8, 2020 at 7:42

1 Answer 1

1
>>> listObj = ['05-19.scl, 05-22.scl, 05-24.scl, 06-41.scl']
>>> a = [x.split(',') for  x in listObj][0]
>>> a
['05-19.scl', ' 05-22.scl', ' 05-24.scl', ' 06-41.scl']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.