Created
April 30, 2014 10:44
-
-
Save vixus0/5b7196a334a1fc25d6f2 to your computer and use it in GitHub Desktop.
Dict of lists -> List of namedtuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
x = {} | |
x['species'] = ['cow', 'pig'] | |
x['sound'] = ['moo', 'oink'] | |
tp_animal = namedtuple('animal', 'species sound') | |
nanimals = 2 | |
animals = [] | |
for i in range(nanimals): | |
d = {k:v[i] for k,v in x.items()} | |
animals.append(tp_animal(**d)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caveats: lists have to be of same (determined) size.