Take the 2-minute tour ×

So here i have a list of numbers of 'Q9ULI0' id. Which is look like this:

['1117', '285', '357', '58', '813', '1398', '566'] 

when i call print lookup['Q9ULI0'] I am trying access all of those value in the index to see if the number is between two of my value. I tried using .len and for loop but it doesn't even compile. Thank you in advance.

lookup = defaultdict(list)

mydata = open('mydata.txt')

for line in csv.reader(mydata, delimiter='\t'):

    code = re.match('[a-z](\d+)[a-z]', line[-1], re.I)
    if code: 

print lookup['Q9ULI0']
share|improve this question
"but it doesn't even compile" -- I assume you mean that there is a syntax error. Can you post the traceback? –  mgilson Jul 12 '12 at 22:48
@mgilson i was testing to see whether i use lookup.len() or code.len() would give me the length of the list but it gives me this error : AttributeError: 'NoneType' object has no attribute 'len' –  Chad D Jul 12 '12 at 22:50
@ChadD I think you want len(lookup) or len(code) –  Samy Vilar Jul 12 '12 at 22:51
Ahh. you could use lookup.__len__(), but it's probably easier to just do len(lookup) –  mgilson Jul 12 '12 at 22:51
@mgilson i guess i had my syntax wrong thanks for reminding me :) –  Chad D Jul 12 '12 at 22:52
show 5 more comments

1 Answer

up vote 1 down vote accepted

If you are able to print lookup['Q9ULI0'] and get the list that you have above, you should have no issues with the following code, which gets the length of the list and loops over it using for:

print len(lookup['Q9ULI0'])
for item in lookup['Q9ULI0']:
    print item
share|improve this answer
thanks it works now –  Chad D Jul 12 '12 at 22:53
add comment

Your Answer


