Q:

python: Find associated value from 2 lists

Sorry to pollute with such a routine question, but:
If I have 2 lists, for example:
list1 = [1,2,3,4,5,6,7]

list2 = [20,40,60,80,100,120,140]

how would I find the value associated with 3 in list1 (answer is 60)
in this case 1 is associated with 20, 2 w/ 40, and so on.

A:

Zip them and make a dictionary.
>>> list1 = [1,2,3,4,5,6,7]
>>> list2 = [20,40,60,80,100,120,140]
>>> dict(zip(list1,list2))
{1: 20, 2: 40, 3: 60, 4: 80, 5: 100, 6: 120, 7: 140}

>>> l = dict(zip(list1,list2))

>>> l[2]
40

>>> l[3]
60

