Generating all combinations

Johannes Bauer dfnsonfsduifb at gmx.de
Sun May 31 16:23:13 EDT 2009


Hello group,

I'm trying to write a function in Python which does the following: For a
number of arguments which are all lists, return a list (or generator)
which yields all tuples of combination. E.g:

foofunction()
# returns [ ]

foofunction([1, 2, 3])
# returns [ (1), (2), (3) ]

foofunction([1, 2, 3], ["a", "b"], ["x"])
# returns [ (1, "a", "x"), (1, "b", "x"),
            (2, "a", "x"), (2, "b", "x"),
            (3, "a", "x"), (3, "b", "x") ]

I must admit that I have no clue on how to do that efficiently (and more
importantly: in a variadic manner) in Python. Any help is appreciated!

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
         -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
                         <48d8bf1d$0$7510$5402220f at news.sunrise.ch>



More information about the Python-list mailing list