generate all combinations of a list (with variable output length)
Mark McEahern
marklists at mceahern.com
Fri Jun 28 16:09:47 EDT 2002
> i'm looking for a way to generate all possible combinations of all items
> in a list. list = ["A","D","$","5","R"]
i don't have a solution, but some questions to clarify:
if you think of your list as comprising the digits, then you're asking for
an n-length string composed of all possible digits where the digits include:
A, D, $, 5, R, and None (the representation of the latter is '')
so, for n = 10, this is a possible value:
AAAAAAAAAA
as well as:
[ ]
omit the brackets.
True?
anyway, this might get you started:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105962
// m
-
More information about the Python-list
mailing list