Re: permuting over nested dicts?
- From: Paddy <paddy3118@xxxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 18:04:13 -0000
On Oct 31, 5:21 pm, Christian Meesters <meest...@xxxxxxxxxxxx> wrote:
Hoi,
I have the following data structure (of variable size actually, to make
things simple, just that one):
d = {'a': {'x':[1,2,3], 'y':[4,5,6]},
'b': {'x':[7,8,9], 'y':[10,11,12]}}
This can be read as a dict of possibilities: The entities 'a' and 'b' have
the parameters 'x' and 'y', each. And d['a']['x'] can be either 1 or 2 or
3. Does anybody know a convenient (and fast) way to permute over all
possible nested dicts like
{'a': {'x':1, 'y':4},
'b': {'x':7, 'y':10}}
and
{'a': {'x':2, 'y':4},
'b': {'x':7, 'y':10}}
and so forth?
Any link or snippet is appreciated.
TIA
Christian
from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502199
import comb2
# (I wish)!
for xa,ya,xb,yb in comb2([1,2,3], [4,5,6], [7,8,9], [10,11,12]):
print {'a': {'x': xa, 'y': ya},
'b': {'x': xb, 'y': yb}}
Should work although untested.
- Paddy.
.
- References:
- permuting over nested dicts?
- From: Christian Meesters
- permuting over nested dicts?
- Prev by Date: Re: _tkinter installation in python 2.5 on mandriva with a default 2.4
- Next by Date: Re: py2exe (or other exe builder) on Vista system for Vista/XP install targets.
- Previous by thread: permuting over nested dicts?
- Index(es):
Relevant Pages
|