Re: Pulling all n-sized combinations from a list

2006-02-17 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: hi, I'm not sure why this hasn't come up yet, but this seems to beg for list comprehensions, if not generator expressions. All of the following run in under 2 seconds on my old laptop: alph = 'abcdefghijklmnopqrstuvwxyz' len([''.join((a,b,c,d)) for a in alph

Re: Pulling all n-sized combinations from a list

2006-02-17 Thread jess . austin
hi, I'm not sure why this hasn't come up yet, but this seems to beg for list comprehensions, if not generator expressions. All of the following run in under 2 seconds on my old laptop: alph = 'abcdefghijklmnopqrstuvwxyz' len([''.join((a,b,c,d)) for a in alph for b in alph for c in alph for d

Re: Pulling all n-sized combinations from a list

2006-02-13 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: But it turns out he actually had one, which he graciously provided in response to my observation. If I had kept my trap shut, I wouldn't have it, would I? I completely agree, but you could put your questions in a way that increases your chances of helpful replies...

Re: Pulling all n-sized combinations from a list

2006-02-13 Thread [EMAIL PROTECTED]
Magnus Lycka wrote: [EMAIL PROTECTED] wrote: But it turns out he actually had one, which he graciously provided in response to my observation. If I had kept my trap shut, I wouldn't have it, would I? I completely agree, but you could put your questions in a way that increases your

Re: Pulling all n-sized combinations from a list

2006-02-13 Thread Steve Holden
[EMAIL PROTECTED] wrote: Magnus Lycka wrote: [EMAIL PROTECTED] wrote: But it turns out he actually had one, which he graciously provided in response to my observation. If I had kept my trap shut, I wouldn't have it, would I? [...] And, strange as it may seem, asking questions the smart way

Re: Pulling all n-sized combinations from a list

2006-02-10 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: But using the free SDK compiler from MS? That seems elusive. Have you seen this? http://www.vrplumber.com/programming/mstoolkit/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Pulling all n-sized combinations from a list

2006-02-10 Thread [EMAIL PROTECTED]
Magnus Lycka wrote: [EMAIL PROTECTED] wrote: But using the free SDK compiler from MS? That seems elusive. Have you seen this? http://www.vrplumber.com/programming/mstoolkit/ I have, although I haven't tried it as I was able to get a GMPY Windows binary from someone else. It may be that

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Jack Diederich
On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have a way to do this that's quite slow, but manageable. I know there must be a better way to do

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread [EMAIL PROTECTED]
Jack Diederich wrote: On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have a way to do this that's quite slow, but manageable. I know there

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: It is a C extension that does permutations combinations and is about 10x faster than doing it in pure python [I'm the author]. It is also the 3rd result for python combination and 5th for python permutaiton but every month someone posts to c.l.py asking for

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Jack Diederich
On Thu, Feb 09, 2006 at 10:23:12AM -0800, [EMAIL PROTECTED] wrote: Jack Diederich wrote: On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: It is a C extension that does permutations combinations and is about 10x faster than doing it in pure python [I'm the author]. It is also the 3rd result for python combination and 5th for python permutaiton but every month someone posts

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: It is a C extension that does permutations combinations and is about 10x faster than doing it in pure python [I'm the author]. It is also the 3rd result for python combination and 5th for python

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: Fredrik Lundh wrote: Windows don't support C ? that was a new one. Windows comes with a C compiler? That's news to me. It doesn't come with Python either. Both Python and the compiler etc that you need can be freely downloaded from the internet. I suggest you leave

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread [EMAIL PROTECTED]
Magnus Lycka wrote: [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: Windows don't support C ? that was a new one. Windows comes with a C compiler? That's news to me. It doesn't come with Python either. Both Python and the compiler etc that you need can be freely downloaded from the

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread [EMAIL PROTECTED]
Jack Diederich wrote: On Thu, Feb 09, 2006 at 10:23:12AM -0800, [EMAIL PROTECTED] wrote: Jack Diederich wrote: On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread Jack Diederich
liberally snipped out parts On Thu, Feb 09, 2006 at 03:25:18PM -0800, [EMAIL PROTECTED] wrote: Jack Diederich wrote: On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements

Re: Pulling all n-sized combinations from a list

2006-02-09 Thread [EMAIL PROTECTED]
Jack Diederich wrote: liberally snipped out parts On Thu, Feb 09, 2006 at 03:25:18PM -0800, [EMAIL PROTECTED] wrote: Jack Diederich wrote: On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote: I've got a reasonably sized list of objects that I'd like to pull out

Pulling all n-sized combinations from a list

2006-02-08 Thread Swroteb
Hi there, I've got a reasonably sized list of objects that I'd like to pull out all combinations of five elements from. Right now I have a way to do this that's quite slow, but manageable. I know there must be a better way to do this, but I'm not sure what it is. Here's what I've got so far:

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Paul Rubin
Swroteb [EMAIL PROTECTED] writes: Atrocious and slow, I'm sure, but is there a better way? I can't simply create a list with the combinations I want, since it won't fit into memory. And I'm sure I can do it using a standard paradigm using five indexed for loops (ie, for i = 1, for j = i+1,

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Swroteb
Paul Rubin wrote: Swroteb [EMAIL PROTECTED] writes: Atrocious and slow, I'm sure, but is there a better way? I can't simply create a list with the combinations I want, since it won't fit into memory. And I'm sure I can do it using a standard paradigm using five indexed for loops (ie,

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Paul Rubin
Swroteb [EMAIL PROTECTED] writes: I'm a little bit confused about your generator suggestion. My list is a set of references to instantiated objects. I'm just unsure about how to iterate through every unique combination of those references. Are you suggesting that I set up methods to provide

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Swroteb
Paul Rubin wrote: I think the natural approach is to make a generator that yields a 5-tuple for each combination, and then have your application iterate over that generator. Here's my version: def comb(x,n): Generate combinations of n items from list x if n==0:

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread my . correo . basura
Ah, this definitely seems to work! It's a lot nicer in appearance than my previous code, that's for sure. It actually runs in approximately the same amount of time though. As a side note, this problem will always be slow. The number of combinations grows exponentially with n. No matter how

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Michael Spencer
Swroteb wrote: Paul Rubin wrote: I think the natural approach is to make a generator that yields a 5-tuple for each combination, and then have your application iterate over that generator. Here's my version: def comb(x,n): Generate combinations of n items from list x

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Paul Rubin
Michael Spencer [EMAIL PROTECTED] writes: This is roughly 30 times faster on my box than the general solution above Good point. You could probably improve the generator version some (probably not 30x) by doing less list arithmetic and slicing though. I just wrote it the most straightforward way

Re: Pulling all n-sized combinations from a list

2006-02-08 Thread Swroteb
Yes, certainly. I hadn't done any profiling up to that point, but it really seemed like my biggest time sink was inefficiently losing time in obtaining the combinations. -- http://mail.python.org/mailman/listinfo/python-list