Re: all possible combinations

2005-07-28 Thread Steve Holden
Steven D'Aprano wrote: > On Thu, 28 Jul 2005 12:30:23 +0100, Steve Holden wrote: > > >>>This makes me wonder why we still don't have something like the unint >>>function above in the standard distribution. >>> >> >>Because it's not what you'd call (or, at least, it's not what I'd call) >>univers

Re: all possible combinations

2005-07-28 Thread Robert Kern
Steven D'Aprano wrote: > Have you looked at what's in the standard Python library? > > aifc.py => Stuff to parse AIFF-C and AIFF files. > imghdr.py => Recognize image file formats based on their first few bytes. > gopher.py => Gopher protocol client interface. > token.py => Token constants (from

Re: all possible combinations

2005-07-28 Thread Steven D'Aprano
On Thu, 28 Jul 2005 12:30:23 +0100, Steve Holden wrote: >> This makes me wonder why we still don't have something like the unint >> function above in the standard distribution. >> > Because it's not what you'd call (or, at least, it's not what I'd call) > universally required. As you have shown

Re: all possible combinations

2005-07-28 Thread Anton Vredegoor
Steve Holden wrote: > > This makes me wonder why we still don't have something like the unint > > function above in the standard distribution. > > > Because it's not what you'd call (or, at least, it's not what I'd call) > universally required. As you have shown it is relatively easy to hack > som

Re: all possible combinations

2005-07-28 Thread Steve Holden
Anton Vredegoor wrote: > John Machin wrote: > > >>You don't need to use random sampling. Paul Rubin has shown how it can >>be done deterministically. The following is a generalisation of his >>code; it generates all possible assemblies of size n from a list of >>parts. Is this helpful? >> >>def a

Re: all possible combinations

2005-07-28 Thread Anton Vredegoor
John Machin wrote: > You don't need to use random sampling. Paul Rubin has shown how it can > be done deterministically. The following is a generalisation of his > code; it generates all possible assemblies of size n from a list of > parts. Is this helpful? > > def all_size_n_knickers(rqd_size, pi

Re: all possible combinations

2005-07-15 Thread rbt
Wow. That's neat. I'm going to use it. Thanks! On Thu, 2005-07-14 at 19:52 -0400, Peter Hansen wrote: > Bengt Richter wrote: > > On Thu, 14 Jul 2005 17:10:37 -0400, William Park <[EMAIL PROTECTED]> wrote: > > It's a one liner in Python too ;-) > > > > >>> print ' '.join([x+y+z+q for s in ['abc']

Re: all possible combinations

2005-07-14 Thread Peter Hansen
Bengt Richter wrote: > On Thu, 14 Jul 2005 17:10:37 -0400, William Park <[EMAIL PROTECTED]> wrote: > It's a one liner in Python too ;-) > > >>> print ' '.join([x+y+z+q for s in ['abc'] for x in s for y in s for z in > s for q in s]) Or for the cost of an import and a lambda, you can keep it loo

Re: all possible combinations

2005-07-14 Thread Bengt Richter
On Thu, 14 Jul 2005 17:10:37 -0400, William Park <[EMAIL PROTECTED]> wrote: >rbt <[EMAIL PROTECTED]> wrote: >> Say I have a list that has 3 letters in it: >> >> ['a', 'b', 'c'] >> >> I want to print all the possible 4 digit combinations of those 3 >> letters: >> >> 4^3 = 64 >> >> >> abaa

Re: all possible combinations

2005-07-14 Thread John Machin
rbt wrote: > Thanks to all who were helpful... some of you guys are too harsh and > cynical. Reality check: wander down to your nearest military establishment, ask a drill sergeant to demonstrate "harsh and cynical". > Here's what I came up with. I believe it's a proper > combination, but I'm su

Re: all possible combinations

2005-07-14 Thread George Sakkis
"rbt" <[EMAIL PROTECTED]> wrote: > Thanks to all who were helpful... some of you guys are too harsh and > cynical. Here's what I came up with. I believe it's a proper > combination, but I'm sure someone will point out that I'm wrong ;) > > groups = [list('abc'),list('abc'),list('abc'),list('abc')]

Re: all possible combinations

2005-07-14 Thread Erik Max Francis
William Park wrote: > Since you're doing cross product (ie. 3*3*3*3), manual loop of 4 level > deep would be the fastest in terms of algorithm. That's a Cartesian product, actually :-). -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W

Re: all possible combinations

2005-07-14 Thread William Park
rbt <[EMAIL PROTECTED]> wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 > > > abaa > aaba > aaab > acaa > aaca > aaac > ... > > What is the most efficient way to do this?

Re: all possible combinations

2005-07-14 Thread Rocco Moretti
rbt wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: When I have occasion to do an iteration of iterations, I either use recursion (already posted) or use an accumulator type loop: items = [

Re: all possible combinations

2005-07-14 Thread Paul Rubin
rbt <[EMAIL PROTECTED]> writes: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: for i in xrange(81): print ''.join(['abcd'[j] for j in [(i//d)%3 for d in (27,9,3,1)]]) -- http:

Re: all possible combinations

2005-07-14 Thread rbt
Thanks to all who were helpful... some of you guys are too harsh and cynical. Here's what I came up with. I believe it's a proper combination, but I'm sure someone will point out that I'm wrong ;) groups = [list('abc'),list('abc'),list('abc'),list('abc')] already = [] while 1: LIST = []

Re: all possible combinations

2005-07-14 Thread John Machin
Steven D'Aprano wrote: > On Thu, 14 Jul 2005 08:49:05 +1000, John Machin wrote: > > >>"You keep using that word. I do not think it means what you think it means." >> >>Both of you please google("define: combination") > > > Combination: "a coordinated sequence of chess moves". > > "An option po

Re: all possible combinations

2005-07-14 Thread Steven D'Aprano
On Thu, 14 Jul 2005 08:49:05 +1000, John Machin wrote: > "You keep using that word. I do not think it means what you think it means." > > Both of you please google("define: combination") Combination: "a coordinated sequence of chess moves". "An option position that is effected by either a purch

Re: all possible combinations

2005-07-14 Thread Thorsten Kampe
* Thomas Bartkus (2005-07-13 20:20 +0100) > "George Sakkis" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> "rbt" <[EMAIL PROTECTED]> wrote: >> >>> Say I have a list that has 3 letters in it: >>> >>> ['a', 'b', 'c'] >>> >>> I want to print all the possible 4 digit combinations of t

Re: all possible combinations

2005-07-13 Thread Edvard Majakari
John Machin <[EMAIL PROTECTED]> writes: >>>My list is not arbitrary. I'm looking for all 'combinations' as I >>>originally posted. Order does not matter to me... just all possibilities. >> That's good, since you only need combinations of "a", "b" and "c" the > "You keep using that word. I do not

Re: all possible combinations

2005-07-13 Thread John Machin
rbt wrote: > On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: > >>Say I have a list that has 3 letters in it: >> >>['a', 'b', 'c'] >> >>I want to print all the possible 4 digit combinations of those 3 >>letters: >> >>4^3 = 64 >> >> >>abaa >>aaba >>aaab >>acaa >>aaca >>aaac >>... >> >>What is the

Re: all possible combinations

2005-07-13 Thread John Machin
Steven D'Aprano wrote: > On Wed, 13 Jul 2005 10:39:41 -0400, rbt wrote: [snip] > Ah, then that's easy. Sit down with pencil and paper, write out all 64 > combinations yourself, and then type them into a Python list. Then you can > access any one of those combinations with a single call. [snip] >>My

Re: all possible combinations

2005-07-13 Thread [EMAIL PROTECTED]
rbt wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 Should be 3**4 = 81. > > > abaa > aaba > aaab > acaa > aaca > aaac > ... > > What is the most efficient way to do this?

Re: all possible combinations

2005-07-13 Thread Thomas Bartkus
"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "rbt" <[EMAIL PROTECTED]> wrote: > > > Say I have a list that has 3 letters in it: > > > > ['a', 'b', 'c'] > > > > I want to print all the possible 4 digit combinations of those 3 > > letters: > > > > 4^3 = 64 > > > It's

Re: all possible combinations

2005-07-13 Thread George Sakkis
"rbt" <[EMAIL PROTECTED]> wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 It's actually 3^4 = 81 (3 candidates/choice ** 4 choices) > > abaa > aaba > aaab > acaa > aaca > a

Re: all possible combinations

2005-07-13 Thread Duncan Smith
Jack Diederich wrote: > On Wed, Jul 13, 2005 at 05:07:33PM +0100, Duncan Smith wrote: > >>rbt wrote: >> >>>On Wed, 2005-07-13 at 11:09 -0400, rbt wrote: >>> >>> On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: >Say I have a list that has 3 letters in it: > >['a', 'b', 'c'] >

Re: all possible combinations

2005-07-13 Thread Jack Diederich
On Wed, Jul 13, 2005 at 05:07:33PM +0100, Duncan Smith wrote: > rbt wrote: > > On Wed, 2005-07-13 at 11:09 -0400, rbt wrote: > > > >>On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: > >> > >>>Say I have a list that has 3 letters in it: > >>> > >>>['a', 'b', 'c'] > >>> > >>>I want to print all the pos

Re: all possible combinations

2005-07-13 Thread Christopher Subich
rbt wrote: > Expanding this to 4^4 (256) to test the random.sample function produces > interesting results. It never finds more than 24 combinations out of the > possible 256. This leads to the question... how 'random' is sample ;) sample(population,k): Return a k length list of unique element

Re: all possible combinations

2005-07-13 Thread Duncan Smith
rbt wrote: > On Wed, 2005-07-13 at 11:09 -0400, rbt wrote: > >>On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: >> >>>Say I have a list that has 3 letters in it: >>> >>>['a', 'b', 'c'] >>> >>>I want to print all the possible 4 digit combinations of those 3 >>>letters: >>> >>>4^3 = 64 >>> >>> >>>a

Re: all possible combinations

2005-07-13 Thread Duncan Smith
rbt wrote: > On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: > >>Say I have a list that has 3 letters in it: >> >>['a', 'b', 'c'] >> >>I want to print all the possible 4 digit combinations of those 3 >>letters: >> >>4^3 = 64 >> >> >>abaa >>aaba >>aaab >>acaa >>aaca >>aaac >>... >> >>What is the

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
On Wed, 13 Jul 2005 11:09:25 -0400, rbt wrote: > On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: >> Say I have a list that has 3 letters in it: >> >> ['a', 'b', 'c'] >> >> I want to print all the possible 4 digit combinations of those 3 >> letters: [snip] > Expanding this to 4^4 (256) to test t

Re: all possible combinations

2005-07-13 Thread rbt
On Wed, 2005-07-13 at 11:09 -0400, rbt wrote: > On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: > > Say I have a list that has 3 letters in it: > > > > ['a', 'b', 'c'] > > > > I want to print all the possible 4 digit combinations of those 3 > > letters: > > > > 4^3 = 64 > > > > > > abaa > >

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
On Wed, 13 Jul 2005 10:39:41 -0400, rbt wrote: >> > What is the most efficient way to do this? >> >> Efficient for who? The user? The programmer? The computer? Efficient use >> of speed or memory or development time? > > The CPU Ah, then that's easy. Sit down with pencil and paper, write out al

Re: all possible combinations

2005-07-13 Thread rbt
On Wed, 2005-07-13 at 10:21 -0400, rbt wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 > > > abaa > aaba > aaab > acaa > aaca > aaac > ... > > What is the most efficient w

Re: all possible combinations

2005-07-13 Thread rbt
On Thu, 2005-07-14 at 00:47 +1000, Steven D'Aprano wrote: > On Wed, 13 Jul 2005 10:21:19 -0400, rbt wrote: > > > Say I have a list that has 3 letters in it: > > > > ['a', 'b', 'c'] > > > > I want to print all the possible 4 digit combinations of those 3 > > letters: > > > > 4^3 = 64 > > > > aa

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
On Wed, 13 Jul 2005 10:21:19 -0400, rbt wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 > > > abaa > aaba > aaab > acaa > aaca > aaac > ... > > What is the most efficient