简体   繁体   中英

How to split sublists of single list in python using split function?

I have a single list and there is multiple sublists so the question is how to split them using split. I can do it using for loop and I think it is a little longer process.

Here is the python code

list =[["a","b","c"],["a","b","c"],[1,2,3]]

separate = list.split(",") 

Here is another way

list =[["a","b","c"],["a","b","c"],[1,2,3]]

separate_one, separate_two, separate_three  = list.split(",") 

print(separate_one)

You are confusing about string and instruction symbol.

Here is what you want.

my_list = [["a","b","c"],["a","b","c"],[1,2,3]]

a, b, c = my_list

print(a)
print(b)
print(c)

the split function will be used as like this

my_string = "I'am, a, monster!"
a, b, c = my_string.split(",")

print(a)
print(b)
print(c)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM