Chad D
Chad D

Reputation: 559

access index of list in the dictionary?

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: 
        lookup[line[-2]].append(code.group(1))

print lookup['Q9ULI0']

Upvotes: 0

Views: 101

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 208505

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

Upvotes: 1

Related Questions