Novice Question: two lists -> dictionary

jwtozer at my-dejanews.com jwtozer at my-dejanews.com
Fri Apr 16 08:12:55 EDT 1999


Thanks to Blake Winton, Quinn Dunkan, frederic pinel, and Alex for your
timely and useful help.  What my associates Visual Basic/Access application
produced in hours, my little Python script produces in seconds.

Jeff




In article <etdd815x3s7.fsf at m2-225-12.mit.edu>,
  Alex <alex at somewhere.round.here> wrote:
>
> You could do something like
>
> **************************************************
> ListA = ['10', '10', '20', '20', '20', '24']
> ListB = ['23', '44', '11', '19', '57', '3']
>
> Dict = {}
> for (key, value) in map (None, ListA, ListB):
>     Dict [key] = Dict.get (key, [])
>     Dict [key].append (value)
>
> print Dict
> **************************************************
>
> The result is
>
> {'24': ['3'], '10': ['23', '44'], '20': ['11', '19', '57']}
>
> See you.
> Alex.
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list