robins02 robins02 - 6 months ago 10
Python Question

Trouble separating lists in order to use an element from it

I am trying to open a file and get the first word from that file
and then compare if it is the same word
i.e. source_index.txt

TTTGATTAAT , source-document01012.txt , 0 , 9
TAATAGTTAG , source-document01012.txt , 6 , 15
TTAGTTTACT , source-document01012.txt , 12 , 21


and get TTTGATTAAT in order to be used later.

extract from code

with open ('source_index.txt', 'r') as fsource:
index1 = [line.strip().split(",") for line in fsource]

with open ('susp_index.txt', 'r') as fsusp:
index2 = [line.strip().split(",") for line in fsusp]

if index1[0] == index2[0]:


by using index1[0], it gives me the whole line. What am I doing wrong?

Answer

This code

with open ('source_index.txt', 'r') as fsource:
    index1 = [line.strip().split(",") for line in fsource]

returns a list of list.

So you should try index[0][0] instead of index[0]

Comments