/ Published in: Python

create a dictionary from the data in two lists
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# [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']}
Comments
