help with code for combinations/permutations

Tim Peters tim.one at home.com
Wed Jan 17 15:26:08 EST 2001


[Bryan Webb]
>     I have a list with 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 in it,
> I need to come up with all possible combinations of the numbers
> in the above
> list ie. 1 +2, 1+2+3, 1+2+3+4, 1+2+3+4+5 and so on.
>  I will have multiple lists to deal with, larger and smaller.
> Any help or ideas will be appreciated

As the replies you got so far suggest, your request is ambiguous, and
"combinations" is a technical term that doesn't appear to be what you really
have in mind.  Give us an exhaustive example with a small list.  Like

x = [1, 2, 3, 4]

Let's pretend you want someone to write a function f(x), that takes a list x
and returns whatever it is you want.  What (exactly) should f([1, 2, 3, 4])
return?

if-english-sufficed-we-wouldn't-need-to-write-programs-ly y'rs  - tim





More information about the Python-list mailing list