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
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):
>
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)
>
[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
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
[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
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.
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
[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
[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
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
<[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
hmmm, just needed better search words, thanks :)
--
http://mail.python.org/mailman/listinfo/python-list
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
<[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
[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
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
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
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
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
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
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
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
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']
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
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
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
"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')]
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
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?
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 = [
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:
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 = []
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
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
* 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
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
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
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
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?
"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
"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
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']
>
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
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
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
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
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
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
> >
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
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
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
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
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
54 matches
Mail list logo