help with code for combinations/permutations

cpsoct at my-deja.com cpsoct at my-deja.com
Sat Jan 20 01:33:03 EST 2001


It is not my question, but if i may be permitted, i think i can ask get
more specific. Or rather try to suggest one possibility. Do you perhaps
mean something that would be like this:

permute(list, n) -- return the nth permutation of a list.

Generates an indexed series of permutations of a list. The permutations
repeat after the factorial of the list size.

x=[1,2,3,4]

permute(x, 0)  --> [1,2,3,4]
permute(x,1)  --> [2,1,3,4]
.
.
.
permute(x,24)  --> [1,2,3,4]


Is this what you mean by permutation fuction? If so that would be most
useful no?

cheers,
kevin parks
seoul, korea

kp87 at lycos.com

ps. I guess that there would have to be a limit to the size of the list
as a 32-bit number would be able to enumerate all the permutations of a
12 element list, but that would be the limit, no? your 16 item list
would be rough going no?

(i am guessing)










In article <mailman.979763239.20136.python-list at python.org>,
  "Tim Peters" <tim.one at home.com> wrote:
> [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
>
>


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list