colbyjackson
colbyjackson

Reputation: 175

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']] 

Upvotes: 0

Views: 72

Answers (2)

Aaditya Ura
Aaditya Ura

Reputation: 12689

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])

Upvotes: 0

Patrick Haugh
Patrick Haugh

Reputation: 61063

listalt = [list(i) for i in list01]

This is a list comprehension, and uses the fact that list can take an iterable (like a string) and turn it into a list

Upvotes: 1

Related Questions