32 lines
735 B
Plaintext
32 lines
735 B
Plaintext
From: alex at somewhere.round.here (Alex)
|
|
Date: 15 Apr 1999 12:11:04 -0400
|
|
Subject: Novice Question: two lists -> dictionary
|
|
References: <7f3j1v$f6j$1@nnrp1.dejanews.com>
|
|
Message-ID: <etdd815x3s7.fsf@m2-225-12.mit.edu>
|
|
X-UID: 1703
|
|
|
|
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.
|
|
|
|
|
|
|
|
|