Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- in python, how do i iterate a nested dict with a dynamic number of nests?
- aDict[1]=[1,2,3]
- aDict[2]=[7,8,9,10]
- aDict[n]=[x,y]
- for l1 in aDict[1]:
- for l2 in aDict[2]:
- for ln in aDict[n]:
- # do stuff with l1, l2, ln combination.
- from itertools import product
- for vals in product(*list(aDict.values())):
- # vals will be (l1, l2, ..., ln) tuple
- from itertools import product
- for vals in product( *[aDict[i] for i in sorted(aDict.keys())]):
- print vals
Add Comment
Please, Sign In to add comment