List as a key to a dictionary

Posted by williamx on Stack Overflow See other posts from Stack Overflow or by williamx
Published on 2010-03-17T14:49:52Z Indexed on 2010/03/17 14:51 UTC
Read the original article Hit count: 446

Filed under:
|

Let's say I have a list:

a = ['apple', 'orange']

and a dictionary:

d ={'apple': [2,4], 'carrot': [44,33], 'orange': [345,667]}

How can I use the list a as a key to lookup in the dictionary d? I want the result to be written to a comma-separated textfile like this

apple,    orange
2,        44
4,        33

© Stack Overflow or respective owner

Related posts about python

Related posts about dictionary