Форум сайта python.su
Есть хеш вида:
h={}
h[1] = [1, 2, 8, 3] # <--- список
h[2] = [4, 11, 8]
#...
h['abc'] = [8, 3, 9, 1, 4]
#...
1, 4,..., 8
1, 4,..., 3
1, 4,..., 9
...
3, 8,..., 4
Офлайн
Например так:
>>> from itertools import product
>>> h={}
>>> h[1] = [1, 2, 8, 3]
>>> h[2] = [4, 11, 8]
>>> h['abc'] = [8, 3, 9, 1, 4]
>>> list(product(*h.values()))
[(1, 4, 8),
(1, 4, 3),
(1, 4, 9),
(1, 4, 1),
(1, 4, 4),
(1, 11, 8),
(1, 11, 3),
(1, 11, 9),
(1, 11, 1),
(1, 11, 4),
(1, 8, 8),
(1, 8, 3),
(1, 8, 9),
(1, 8, 1),
(1, 8, 4),
(2, 4, 8),
(2, 4, 3),
(2, 4, 9),
(2, 4, 1),
(2, 4, 4),
(2, 11, 8),
(2, 11, 3),
(2, 11, 9),
(2, 11, 1),
(2, 11, 4),
(2, 8, 8),
(2, 8, 3),
(2, 8, 9),
(2, 8, 1),
(2, 8, 4),
(8, 4, 8),
(8, 4, 3),
(8, 4, 9),
(8, 4, 1),
(8, 4, 4),
(8, 11, 8),
(8, 11, 3),
(8, 11, 9),
(8, 11, 1),
(8, 11, 4),
(8, 8, 8),
(8, 8, 3),
(8, 8, 9),
(8, 8, 1),
(8, 8, 4),
(3, 4, 8),
(3, 4, 3),
(3, 4, 9),
(3, 4, 1),
(3, 4, 4),
(3, 11, 8),
(3, 11, 3),
(3, 11, 9),
(3, 11, 1),
(3, 11, 4),
(3, 8, 8),
(3, 8, 3),
(3, 8, 9),
(3, 8, 1),
(3, 8, 4)]
Офлайн
Спасибо. То что нужно + в документации по product можно посмотреть, как он мог бы быть реализован на Питоне. Да, тему выбрал не совсем удачно.
http://docs.python.org/library/itertools.html#itertools.product
Офлайн