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']
Here's one way:
new_list = []
for x in my_list:
new_list += [a.strip() for a in x.split(",")]
这里是
new_list = [j.strip() for i in my_list for j in i.split(',')]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.