Cheeseburgler
Cheeseburgler

Reputation: 31

splitting a list into lists

If I have obtained the following list as an output from a csv file:

[g1,g2,g3] [g2,g3,g4] [g3,g4,g5]

Via this code:

def KnockOut(cmod):
    f = open('csv.txt','r')
    for line in f.readlines():
        stripped_line = line.rstrip()
        genelist = stripped_line.split(',') 

Now it seems whenever I iterate over genelist, I always iterate over all the 3 lists. My goal is to iterate over each list independently (and perform a function on all the 3 genes contained in the list). How can I split? this list into separate lists?

Cheers, Jordy

Upvotes: 0

Views: 82

Answers (1)

Selcuk
Selcuk

Reputation: 59445

You can access each element using its index (starting from 0):

for gene in genelist:
    g1 = gene[0]
    g2 = gene[1]
    g3 = gene[2]
    ...do something with g1, g2 and g3...

Upvotes: 1

Related Questions