Re: iterator? way of generating all possible combinations?

2006-05-31 Thread Scott David Daniels
Jim Segrave wrote: > In article <[EMAIL PROTECTED]>, > Scott David Daniels <[EMAIL PROTECTED]> wrote: >> class FileReIterable2(object): >> ... >> def __iter__(self): >> self.file.seek(0) >> for line in self.file: >> nextpos = self.file.te

Re: iterator? way of generating all possible combinations?

2006-05-31 Thread Jim Segrave
In article <[EMAIL PROTECTED]>, Scott David Daniels <[EMAIL PROTECTED]> wrote: > >This works if-and-only-if it is only in use once at a time. >If you have multiple simultaneous accesses, you need to do >something like: > > class FileReIterable2(object): > def __init__(self, file): >

Re: iterator? way of generating all possible combinations?

2006-05-31 Thread [EMAIL PROTECTED]
Scott David Daniels wrote: > [EMAIL PROTECTED] wrote: > > Scott David Daniels wrote: > >> Sorry, "re-iterables". A file re-iterable is: > >> > >> class FileReIterable(object): ... > >> def __iter__(self): > >> self.file.seek(0) > >> return iter(self.file) >

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Scott David Daniels wrote: >> Sorry, "re-iterables". A file re-iterable is: >> >> class FileReIterable(object): ... >> def __iter__(self): >> self.file.seek(0) >> return iter(self.file) >> >> This works if-and-only-if it is only in

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread [EMAIL PROTECTED]
Scott David Daniels wrote: > Sorry, "re-iterables". A file re-iterable is: > > class FileReIterable(object): > def __init__(self, file): > if isinstance(file, basestring): > self.file = open(file, 'rU') > else: > self.file

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Scott David Daniels wrote: > >> This works with "iterables" (and produces), rather than "iterators", >> which is vital to the operation. >> >> --Scott David Daniels >> [EMAIL PROTECTED] > > Sorry, it doesn't. It works with strings. It doesn't work with file, > it does

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread [EMAIL PROTECTED]
Scott David Daniels wrote: > This works with "iterables" (and produces), rather than "iterators", > which is vital to the operation. > > --Scott David Daniels > [EMAIL PROTECTED] Sorry, it doesn't. It works with strings. It doesn't work with file, it doesn't work with iterators I have created.

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread [EMAIL PROTECTED]
This would only work for combinations of identical sets, and also does not seem to work with generated sets, or iterators. Forgetting dice for a moment. Say I have 3 very long files, and i want to generate the combinations of lines in the files. This provides a well known iterator for the exampl

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > However, none of the algo's I have checked will work with generated > sequences, or iterable classes, as posited in my first post. > > While appropriate to the current domain, ie dice. What if you want > combinations of extrememely large lists, say 3 sets of 10 mil item

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > > > Well thanks for the mathematical restatement of my problem. I had > forgotten the proper terms. Searching on those terms generates some > interesting results. > > However, none of the algo's I have checked will work with generated > sequences, or iterable classe

Re: iterator? way of generating all possible combinations?

2006-05-30 Thread [EMAIL PROTECTED]
Well thanks for the mathematical restatement of my problem. I had forgotten the proper terms. Searching on those terms generates some interesting results. However, none of the algo's I have checked will work with generated sequences, or iterable classes, as posited in my first post. While app

Re: iterator? way of generating all possible combinations?

2006-05-27 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Terry Reedy wrote: > >> >> Are the dice identical or distinguishable (marked). In other words, >> with 2 >> dice, is 1,2 the same as 2,1 or different? Note that in most dice >> games, >> such as craps, the dice are not distinguis

Re: iterator? way of generating all possible combinations?

2006-05-26 Thread [EMAIL PROTECTED]
hmmm, just needed better search words, thanks :) -- http://mail.python.org/mailman/listinfo/python-list

Re: iterator? way of generating all possible combinations?

2006-05-26 Thread [EMAIL PROTECTED]
Terry Reedy wrote: > > Are the dice identical or distinguishable (marked). In other words, with 2 > dice, is 1,2 the same as 2,1 or different? Note that in most dice games, > such as craps, the dice are not distinguished, but probability calculations > must treast them as if they were to get th

Re: iterator? way of generating all possible combinations?

2006-05-26 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ok, this is really irritating me. I'm sure there are different ways of > doing this - I'm interested in the algo, not the practical solution, > I'm more trying to play with iterators and recursion. I want to create > a program that g

Re: iterator? way of generating all possible combinations?

2006-05-26 Thread Raymond Hettinger
[EMAIL PROTECTED] wrote: > Ok, this is really irritating me. I'm sure there are different ways of > doing this - I'm interested in the algo, not the practical solution, > I'm more trying to play with iterators and recursion. I want to create > a program that generates every possible combination

iterator? way of generating all possible combinations?

2006-05-26 Thread [EMAIL PROTECTED]
Ok, this is really irritating me. I'm sure there are different ways of doing this - I'm interested in the algo, not the practical solution, I'm more trying to play with iterators and recursion. I want to create a program that generates every possible combination of a set of a n dice, with s sides

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

all possible combinations

2005-07-13 Thread rbt
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? -- http://mail.python.org/mailman/listinfo/python-list