简体   繁体   中英

How to make a list to split into each element and make a sublist

If I have this list,

list01 = ['GAGGT','TCCGT','ABECF']

I want to make each element in the list to split, but still remain in the same box of list. Like this:

listalt = [['G','A','G','G','T'],['T','C','C','G','T'],['A','B','E','C','F']] 
listalt = [list(i) for i in list01]

这是一个列表理解 ,并利用list可以采用可迭代(如字符串)并将其转换为list事实

You can use this :

final_list=[]
for item in list01:
    final_list.append(list(item))

print(final_list)

which is same as :

print([list(item) for item in list01])

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