Revision: 21849
Updated Code
at November 10, 2010 22:06 by magicrebirth
Updated Code
# [PSST] Copied for good measure ListA = ['10', '10', '20', '20', '20', '24'] ListB = ['23', '44', '11', '19', '57', '3'] d = {} for a, b in map(None, ListA, ListB): if not d.has_key(a): d[a] = [b] else: d[a].append(b) print d # result: {'24': ['3'], '10': ['23', '44'], '20': ['11', '19', '57']}
Revision: 21848
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 22, 2009 15:10 by magicrebirth
Initial Code
# [PSST] Copied for good measure ListA = ['10', '10', '20', '20', '20', '24'] ListB = ['23', '44', '11', '19', '57', '3'] d = {} for a, b in map(None, ListA, ListB): if not d.has_key(a): d[a] = [b] else: d[a].append(b) print d
Initial URL
Initial Description
create a dictionary from the data in two lists
Initial Title
Python: from two lists to a dictionary
Initial Tags
list, python
Initial Language
Python