left brain and right brain permutations

2009-06-15 Thread pataphor
left brain: Generate permutations by index, see previous newsgroup posts. Code not now available here. They are very pragmatic and practical, can start right away, and can be efficiently spread over many independent computing cores. right brain: from itertools import izip, chain from math

Re: Making the case for repeat

2009-06-05 Thread pataphor
Gabriel Genellina wrote: > Ok, you're proposing a "bidimensional" repeat. I prefer to keep things > simple, and I'd implement it in two steps. But what is simple? I am currently working on a universal feature creeper that could replace itertools.cycle, itertools.repeat, itertools.chain and rever

Re: Making the case for repeat

2009-06-04 Thread pataphor
Steven D'Aprano wrote: > I've run your test code, and I don't know what I'm supposed to be > impressed by. Thank you for trying out the code. That you're unimpressed actually is a huge encouragement because code should just run the way people expect, without unnecessary surprises. P. -- http:/

Making the case for repeat

2009-06-04 Thread pataphor
This probably has a snowballs change in hell of ending up in builtins or even some in some module, but such things should not prevent one to try and present the arguments for what one thinks is right. Else one would end up with consequentialism and that way lies madness and hyperreality. So here i

Re: Generating all combinations

2009-06-01 Thread pataphor
Mensanator wrote: I couldn't do that if they weren't subsets. Right. Sometimes one just has to assume things are different even if they look the same on the surface. That is because else one wouldn't be able to produce the other generators. I guess it would also work the other way around, a

Re: Generating all combinations

2009-06-01 Thread pataphor
Johannes Bauer wrote: Any help is appreciated! This is on the fringe of exploitation, but hey, maybe the code helps you think about the algorithm. IMHO the following code is a glaring complaint about the injustice of omission itertools inflicts on the perfectly natural and obvious procedu

Re: itertools question

2009-05-15 Thread pataphor
Neal Becker wrote: Is there any canned iterator adaptor that will transform: in = [1,2,3] into: out = [(1,2,3,4), (5,6,7,8),...] That is, each time next() is called, a tuple of the next N items is returned. Here's one that abuses a for loop: from itertools import islice def grouper(

Re: more fun with iterators (mux, demux)

2009-04-08 Thread pataphor
On Wed, 08 Apr 2009 10:51:19 -0400 Neal Becker wrote: > What was wrong with this one? > > def demux(iterable, n): > return tuple(islice(it, i, None, n) for (i, it) in > enumerate(tee(iterable, n))) Nothing much, I only noticed after posting that this one handles infinite sequences too. For

Re: more fun with iterators (mux, demux)

2009-04-08 Thread pataphor
On 07 Apr 2009 02:05:59 GMT Steven D'Aprano wrote: > The demuxer can't be an iterator, since it needs to run through the > entire collection. Then your demuxer obviously cannot handle infinite sequences. > def demux(it, n): > collectors = [[] for i in xrange(n)] > i = 0 > for item

Re: Ordered Sets

2009-03-31 Thread pataphor
On Tue, 31 Mar 2009 06:03:13 -0700 (PDT) Alex_Gaynor wrote: > My inclination would be to more or less *just* have it implement the > set API, the way ordered dict does in 2.7/3.1. As far as I can tell all that would be needed is read/write access to two key variables: The iterator start position

Re: Ordered Sets

2009-03-31 Thread pataphor
On Tue, 31 Mar 2009 10:33:26 +0200 pataphor wrote: > On Mon, 30 Mar 2009 19:57:39 -0700 (PDT) > Alex_Gaynor wrote: > > > I really like the Ordered Set class(I've been thinking about one > > ever since ordered dict hit the std lib), is there any argument >

Re: Ordered Sets

2009-03-31 Thread pataphor
On Mon, 30 Mar 2009 19:57:39 -0700 (PDT) Alex_Gaynor wrote: > I really like the Ordered Set class(I've been thinking about one ever > since ordered dict hit the std lib), is there any argument against > adding one to the collections module? I'd be willing to write a PEP > up for it. Suppose the

Re: Ordered Sets

2009-03-30 Thread pataphor
On Mon, 30 Mar 2009 03:30:04 -0500 Nick Craig-Wood wrote: > >>> class Node(object): > ... __slots__ = ["prev", "next", "this"] > ... def __init__(self, prev, next, this): > ... self.prev = prev > ... self.next = next > ... self.this = this [...] > So the Node cla

Re: Ordered Sets

2009-03-26 Thread pataphor
Raymond Hettinger wrote: Right. Here's a link to a weakref version (though I think the previous __del__ version also does the trick): http://code.activestate.com/recipes/576696/ Interesting. But how about this one? Does it also have the reference problem? By the way collections.MutableS

KeyedList

2009-02-28 Thread pataphor
The ordered dictionary discussion made me think of another data type which seems to be somewhat related, a kind of ordered dictionary where the order of the items is arbitrary. One can insert items in the middle and still have O(1) access (I think). I have provided a very basic implementation, it c

Re: Counter Class -- Bag/Multiset

2009-01-24 Thread pataphor
On Thu, 22 Jan 2009 10:11:37 -0800 (PST) Raymond Hettinger wrote: > The collections module in Python 2.7 and Python 3.1 has gotten a new > Counter class that works like bags and multisets in other languages. I like that! Now that we have a multiset or Counter I think a redefinition of itertools.

Re: [ANN] XPN 1.2.5

2008-09-18 Thread pataphor
Nemesis wrote: > XPN (X Python Newsreader) is a multi-platform newsreader with Unicode > support. It is written with Python+GTK. It has features like > scoring/actions, X-Face and Face decoding, muting of quoted text, > newsrc import/export, find article and search in the body, spoiler > char/rot1

Re: How to emit Cyrillic and Chinese via unicode from console mode?

2008-09-14 Thread pataphor
On Sun, 14 Sep 2008 01:02:39 -0700 (PDT) rs387 <[EMAIL PROTECTED]> wrote: > On Sep 14, 2:03 am, "Siegfried Heintze" <[EMAIL PROTECTED]> wrote: > > Can someone point me to an example of a little program that emits > > non-ascii Unicode characters (Russian or Chinese perhaps)? > > The following doe

Re: multiprocessing module (PEP 371)

2008-06-05 Thread pataphor
In article <877a5774-d3cc-49d3-bb64-5cab8505a419 @m3g2000hsc.googlegroups.com>, [EMAIL PROTECTED] says... > I don't see pyprocessing as a drop-in replacement for the threading > module. Multi-threading and multi-processing code tend to be > different, unless something like mutable objects in share

Re: "indexed properties"...

2008-05-22 Thread pataphor
On Thu, 22 May 2008 06:26:41 -0500 David C. Ullrich <[EMAIL PROTECTED]> wrote: > On Wed, 21 May 2008 12:47:44 +0200, pataphor <[EMAIL PROTECTED]> > wrote: > >Using the trick of encapsulating the values inside single-element > >lists one can make a trans

Re: "indexed properties"...

2008-05-21 Thread pataphor
On Tue, 20 May 2008 10:40:17 -0500 "David C. Ullrich" <[EMAIL PROTECTED]> wrote: > > > Today's little joke: Long ago I would have solved > > > this by storing the data as a list of rows and _also_ > > > a list of columns, updating each one any time the > > > other changed. Just goes to show you th

Re: "indexed properties"...

2008-05-20 Thread pataphor
On Tue, 20 May 2008 06:12:01 -0500 David C. Ullrich <[EMAIL PROTECTED]> wrote: > Well, ok. Like I said, I never _took_ the position that it _should_ > be a list of lists, I just said I didn't see the advantage to using > a single list. I'm now thinking about a list of lists containing single elem

Re: Write bits in file

2008-05-20 Thread pataphor
On Sun, 18 May 2008 06:36:28 -0700 (PDT) Monica Leko <[EMAIL PROTECTED]> wrote: > Yes. I need arbitrary, 8bits, than 10 bits for something else, than > sequence of bytes, than 10 bits again, etc. Here's something to get you started. No guarantees, but I managed to write four 10 bit numbers to a

Re: "indexed properties"...

2008-05-19 Thread pataphor
On Mon, 19 May 2008 06:29:18 -0500 David C. Ullrich <[EMAIL PROTECTED]> wrote: > Maybe you could be more specific? Various "positions" I've > taken in all this may well be untenable, but I can't think > of any that have anything to do with whether the data should > be a single list instead of a li

Re: "indexed properties"...

2008-05-18 Thread pataphor
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > Is there some reason that would be better? It would make a lot > of the code more complicated. Ok, it would require only one > bit of added code, I suppose, but I don't see the plus side. The plus side is you give up an untenable positi

Re: "indexed properties"...

2008-05-17 Thread pataphor
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > >> window.pos = (x,y) > >> > >> seems more natural than > >> > >> window.SetPos(x,y); Yes, and to assign a row in a matrix I'd also like to use either tuples or lists on the right side. > def __add__(self, other): > return

Re: Combinatorics

2008-02-12 Thread pataphor
On Mon, 11 Feb 2008 23:52:31 -0800 Michael Robertson <[EMAIL PROTECTED]> wrote: > Am I wishing on a star? for i in xrange(10**10): print i OverflowError: long int too large to convert to int The problem seems to be that although python supports arbitrary long integers, all the internal loop

Re: breaking out of outer loops

2008-01-29 Thread pataphor
On Tue, 29 Jan 2008 11:51:04 -0800 (PST) [EMAIL PROTECTED] wrote: > Any elegant way of breaking out of the outer for loop than below, I > seem to have come across something, but it escapes me > > for i in outerLoop: >for j in innerLoop: >if condition: > break >else: >

Re: sudoku solver in Python ...

2008-01-24 Thread pataphor
On Thu, 24 Jan 2008 21:09:42 +0100 Thomas Thiel <[EMAIL PROTECTED]> wrote: > Neither fast nor user friendly, but very concise: This is a bit faster: options = set([str(i) for i in range(1, 10)]) def allow(puzzle,i): exclude = set(x if i//9 == j//9 or i%9 == j%9 or i//27 == j//27 an