Re: What happened to __cmp__() in Python 3.x?

2009-08-16 Thread Raymond Hettinger
[Xavier Ho] > > I've recently made my way to Python 3.1 and I'm not seeing __cmp__() in the > > documentation. > > > Is there a substitution for this special method in 3.1, or do I really have > > to define all six rich comparison methods to work it out? FWIW, there is a recipe for expanding the c

Re: Social problems of Python doc [was Re: Python docs disappointing]

2009-08-17 Thread Raymond Hettinger
[Xah Lee] > This part i don't particular agree: > > > * The reason for implementing the key= parameter had nothing to do > > with limitations of Python's compiler.  Instead, it was inspired by > > the > > decorate-sort-undecorate pattern. > > The decorate-sort-undecorate pattern is a compiler limi

Re: #elements of seq A in seq B

2009-08-20 Thread Raymond Hettinger
On Aug 19, 4:19 pm, Neal Becker wrote: > What would be a time efficient way to count the number of occurrences of > elements of sequence A in sequence B?  (in this particular case, these > sequences are strings, if that matters). Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit

Re: #elements of seq A in seq B

2009-08-20 Thread Raymond Hettinger
On Aug 19, 4:19 pm, Neal Becker wrote: > What would be a time efficient way to count the number of occurrences of > elements of sequence A in sequence B?  (in this particular case, these > sequences are strings, if that matters). Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit

Re: Simple addition to random module - Student's t

2009-09-02 Thread Raymond Hettinger
On Sep 2, 6:51 am, Thomas Philips wrote: > While the random module allows one to generate randome numbers with a > variety of distributions, some useful distributions are omitted - the > Student's t being among them. I'm curious to hear what your use cases are. My understanding is that t-distrib

Re: Simple addition to random module - Student's t

2009-09-02 Thread Raymond Hettinger
> To get this into core Python, you'd usually submit a feature request > athttp://bugs.python.org. If you do submit a patch, please assign it to me. I've been the primary maintainer for that module for several years. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-02 Thread Raymond Hettinger
> I dont know guppy, > but if h.load(f) raises StopIteration upon eof, as seems implied by your > proposal, then something like the following would work. > > sets.extend(h.load(f) for _ in xrange(1e9)) Sounds like hpy has a weird API. Either it should be an iterator supporting __iter__() and nex

Re: Performance: sets vs dicts.

2010-08-29 Thread Raymond Hettinger
On Aug 29, 12:12 pm, John Nagle wrote: >     Is the "in" test faster for a dict or a set? > Is "frozenset" faster than "set"?  Use case is > for things like applying "in" on a list of 500 or so words > while checking a large body of text. There is no significant difference. All three are implemen

Re: in place functions from operator module

2010-08-29 Thread Raymond Hettinger
On Aug 29, 8:33 am, Arnaud Delobelle wrote: > ernest writes: > > Hi, > > > The operator module provides separate functions for > > "in place" operations, such as iadd(), isub(), etc. > > However, it appears that these functions don't really > > do the operation in place: > > > In [34]: a = 4 > >

Re: Performance: sets vs dicts.

2010-09-01 Thread Raymond Hettinger
On Aug 30, 6:03 am, a...@pythoncraft.com (Aahz) wrote: > That reminds me: one co-worker (who really should have known better ;-) > had the impression that sets were O(N) rather than O(1).  Although > writing that off as a brain-fart seems appropriate, it's also the case > that the docs don't really

How Python works: What do you know about support for negative indices?

2010-09-09 Thread Raymond Hettinger
Hello Folks. It doesn't seem to be common knowledge when and how a[x] gets translated to a[x+len(x)]. So, here's a short info post on how Python supports negative indices for sequences. I've put the answer below, but if you want to quickly test your own knowledge, ask yourself which of these sup

Re: How Python works: What do you know about support for negative indices?

2010-09-13 Thread Raymond Hettinger
[Ben Finney] > I encourage anyone whose messages are munged like that to seek > correction from their mail service provider, and switch to a different > one until it's fixed. The post was typed on a mobile device into the text window on Google Groups. It's too bad that inane concerns with newline

Re: How Python works: What do you know about support for negative indices?

2010-09-13 Thread Raymond Hettinger
On Sep 10, 2:13 pm, Terry Reedy wrote: > Reading the third paragraph out of context, one can miss the restriction > to built-in objects. I had assumed that the conversion using len(), when > available, happened prior to the __getitem__ call. Yes, that's a common misconception. It is probably ba

Re: Combinations or Permutations

2010-09-21 Thread Raymond Hettinger
On Sep 20, 1:54 pm, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a list of variables: > > [a,b,c,d,...,x,y,z] > > I am curious if there is an optimized way to generate this: > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]]

Re: Overriding dict constructor

2010-09-21 Thread Raymond Hettinger
[Steven D'Aprano] > But if I try to create a regular dict from this, dict() doesn't call my > __getitem__ method: > > >>> dict(d) > > {0: ('a', 'extra_data'), 1: ('b', 'extra_data')} > > instead of {0: 'a', 1: 'b'} as I expected. > > How can I fix this? Try using dict(d.items()). Raymond -- ht

Re: ConFoo spam?

2010-10-08 Thread Raymond Hettinger
On Oct 7, 10:01 am, Jack Diederich > [For the record > ConFoo /does/ interest me, but I can't take a week and a half off to > do that plus PyCon]. CooFoo is an excellent conference. Even in the non-python tracks, there are plenty of high quality talks that would be of interest to people tracking

Nested Mapping

2010-10-21 Thread Raymond Hettinger
I'm considering a nested mapping class for the collections module and would like to solicit feedback from people here on comp.lang.python: http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ The class is an attempt to generalize from existing use cases (i.e.

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 4:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > What I really want is a Haskell-like persistent (i.e. purely functional) > dictionary implemented as an AVL tree or something like that. Hopefully, that discussion can be in a separate thread. This is really about ke

Re: Nested Mapping

2010-10-21 Thread Raymond Hettinger
On Oct 21, 5:18 pm, Paul Rubin wrote: > The API you suggested looks reasonable although you should also say how > to delete a context, how to find the inner contexts of a context, etc. The c.parent.parent.parent chain finds successive enclosing contexts: while c.parent is not None: pri

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 22, 4:17 am, Peter Otten <__pete...@web.de> wrote: > I just read the recipe, and it looks good to me except for the len() and > iter() implementations: > > >>> a = Context() > >>> a["x"] = 1 > >>> b = a.new_child() > >>> b["x"] = 2 > >>> len(b) > 2 > >>> b.keys() > > ['x', 'x'] > > I would h

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 22, 8:48 am, Robert Kern wrote: > On 10/21/10 6:19 PM, Raymond Hettinger wrote: > > > I would appreciate any feedback on the API and on how well it fits > > with various use cases that you've found in the wild. > > We've done something similar in the past:

Re: Nested Mapping

2010-10-22 Thread Raymond Hettinger
On Oct 21, 6:13 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > The c.parent.parent.parent chain finds successive enclosing contexts: > > I was asking about finding the child contexts, not the parents.  This is > analogous to how you can find the keys in a dict with dict

Re: Why "flat is better than nested"?

2010-10-27 Thread Raymond Hettinger
On Oct 25, 8:23 am, Steve Holden wrote: > And everyone taking the Zen too seriously should remember that it was > written by Tim Peters one night during the commercial breaks between > rounds of wrestling on television. So while it can give useful guidance, > it's nether prescriptive nor a bible .

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
>  Shashank Singh wrote: > > > Are there any promises made with regard to final state of the underlying > > sequence that islice slices? Currently, there are no promises or guarantees about the final state of the iterator. To the extent the pure Python version in the docs differs from the CPytho

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 1:05 pm, Terry Reedy wrote: > > Currently, there are no promises or guarantees about the final state > > of the iterator. > > I interpret the current doc statement as a promise that becomes > ambiguous when step > 1. You may have missed my point. I wrote the tools, the docs, and the te

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 3:52 pm, Ian wrote: > On Nov 5, 2:51 pm, Raymond Hettinger wrote: > > > You may have missed my point.  I wrote the tools, the docs, and the > > tests. > > If you interpret a "promise" in text, I can assure you it was not > > intended.  The

Re: Split iterator into multiple streams

2010-11-06 Thread Raymond Hettinger
On Nov 6, 1:52 am, Steven D'Aprano wrote: > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): >     iterators = [] >     for i, iterator in enumerate(itertools.tee(iterable, n)): >         f = lambda it, i=i: (t[i] for t in

Is a 32-bit build faster than a 64-bit build

2010-11-12 Thread Raymond Hettinger
Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for Django or some other webserver? My hypotheses is that for apps not needing the 64-bit address space, the 32-bit version has better memory utilization and hence better cache performance. If so, then switching python versions ma

<    3   4   5   6   7   8