Reputation: 559
I have the follwoing list:
my_list = ['1', '7', '9, 11', '14']
How do I unnest comma-separated items like so:
new_list = ['1', '7', '9', '11', '14']
Upvotes: 0
Views: 128
Reputation: 6279
Here it is
new_list = [j.strip() for i in my_list for j in i.split(',')]
Upvotes: 2
Reputation: 49803
Here's one way:
new_list = []
for x in my_list:
new_list += [a.strip() for a in x.split(",")]
Upvotes: 2