All combinations of a list
June Kim
junaftnoon at nospamplzyahoo.com
Mon Oct 23 04:11:42 EDT 2000
Below is my first version of doing it:
def comb(list):
if len(list) ==0:
return [[]]
return [ [[list[0]],[]][i]+c for i in (0,1) \
for c in comb(list[1:]) ]
That works fine, but why does another version using
lambda give a subscription error?
def comb(list):
if len(list) ==0:
return [[]]
return map(lambda x: [list[0]]+x , comb(list[1:])) \
+ comb(list[1:])
Thanks in advance.
June
[This thread was first started from permutation lists
and now that the topic has moved somewhat far from
the originator's question, I open up this thread as a new one]
More information about the Python-list
mailing list