J
Johannes Bauer
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
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