[Tutor] Creating a dictionary on user filter

Mike Nickey mnickey at gmail.com
Fri Jul 20 01:38:53 CEST 2012


Hi All,

I have a few lists that I'm trying to put into a dictionary based on
which list the user wants to use as a filter. If the user selects 1
the the dictionary would be created using the first list as the keys
and the secondary items as the values. If the user selects 2, the
dictionary would be created with the second list as the keys, and the
remaining as the values. I think using dict(zip(firstList,
(secondList, thirdList))) is the way to go but I'm having trouble with
the placement of the items.

What I have is this:
firstList = ['a', 'b', 'c']
secondList = [1,2,3]
thirdList = [1.20, 1.23, 2.54]

What I am looking for is something like this for output:
{'a': [1, 1.20], 'b': [2, 1.23], 'c': [3, 2.54]}

What I'm now thinking is that I need to loop over each item in the
list and update the dictionary such as:
for x in range(a):
    compilation = dict(zip(a[x], (b[x], c[x])))

Any help is appreciated.

-- 
~MEN


More information about the Tutor mailing list