May 19, 2010

[Python] Joining two lists in a dictionary

Hello and welcome everybody.
First entry, so something pythonic for starters. Simple function for joining two lists in a dictionary. If anyone has better idea, leave a comment.



def mapper(keys, values):
n = len(keys)
return [dict(zip(keys, values[i:i + n]))
for i in range(0, len(values), n)]

No comments:

Post a Comment