some sort of permutations...

Bernard A. bernadal2008 at yahoo.fr
Tue Apr 12 02:28:02 EDT 2005


hello,

i'm looking for a way to have all possible length fixed n-uples from a
list, i think generators can help, but was not able to do it myself,
maybe some one could point me out to an idea to do it ?

for example, from :
l = [0, 1, 2, 3, 4]

and searching for n-uples of 3, i should produce :
(
(0, 1, 2),
(0, 1, 3),
(0, 1, 4),
(0, 2, 3),
(0, 2, 4),
(0, 3, 4),
(1, 2, 3),
(1, 2, 4),
(1, 3, 4),
(2, 3, 4),
)

does the set module or itertools can help in such cases ? i still have
missed the black magic behind itertools...

best regards



More information about the Python-list mailing list