Re: faster than list.extend()

2009-11-16 Thread Raymond Hettinger
erable, izip=izip): return list(chain_from_iterable(izip(inputlist, inputlist, inputlist))) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: python bijection

2009-11-21 Thread Raymond Hettinger
which looks the best in real code. It cannot be error-prone or it is doomed. Also, it should not introduce much overhead processing or else people will avoid it. The API should be trivially simple so that people remember how to use it months after seeing it for the first time. Good luck and happy hunting, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Your impression of for-novice writings on assertions

2010-02-02 Thread Raymond Hettinger
se an assertion for sanity checking by verifying an expected mathematical relationship such as the triangle inequality: assert abs(c) <= abs(a) + abs(b). The pythagorean triple example can use assertions to check post conditions: assert all(isinstance(x, int) for x in (a,b,c)) and a*a +b*b==c

Selenium/SauceLabs OpenSpace at Pycon

2010-02-03 Thread Raymond Hettinger
or of Selenium (an open source web app testing tool http://seleniumhq.org/ ). Several familiar names from the Python community will also be on-hand: http://saucelabs.com/about/news/feb-03-2010 Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Selenium/SauceLabs OpenSpace at Pycon

2010-02-04 Thread Raymond Hettinger
> >For those who are interested, the Sauce Labs team, > >http://saucelabs.com/about/team, is hosting two free tutorial open > >space sessions at Pycon in Atlanta. [Aahz] > Congrats on the new job! Thanks. I'm really enjoying working with Jim Baker and Frank Wierz

Re: method to intercept string formatting % operations

2010-02-05 Thread Raymond Hettinger
Since automatic conversion is out, you can instead use the namedtuple._asdict() method for an explicit conversion: >>> from collections import namedtuple >>> Point = namedtuple('Point', 'x y') >>> p = Point(5, 12) >>> 'x: %(x)s' % p._asdict() 'x: 5' Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3: Plist as OrderedDict

2010-02-08 Thread Raymond Hettinger
e to monkey patch an OrderedDict into the PlistParser. Here's an untested stab at it: from collections import OrderedDict import plistlib plistlib._InteralDict = OrderedDict Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: To (monkey)patch or not to (monkey)patch, that is the question

2010-02-09 Thread Raymond Hettinger
is changed. IOW, monkey patching is a fragile technique for a large project. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: collections use __next__() in python 2.6?

2010-02-26 Thread Raymond Hettinger
thon 3. Also, I'm using the Mapping ABC, > which inherits from Iterable, and it doesn't seem to work if I define > __next__(); I am not seeing problems if I define next() instead. > > What am I missing? It's a typo. The abstract method is next(). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: random.gauss: range

2010-02-26 Thread Raymond Hettinger
, so mu and sigma don't really tell me a thing. Try random.randrange() and random.triangular(). They are both easy to use and do not require you to enter parameters that you don't understand. FWIW, mu and sigma refer to the average and standard deviation of a normal distribution.

Re: Queue peek?

2010-03-02 Thread Raymond Hettinger
return if you don't need it? val = q.peek() if not something_i_want(val): q.put(val) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: negative "counts" in collections.Counter?

2010-03-07 Thread Raymond Hettinger
MyCounter(Counter): def __sub__(self, other): result = self.copy() for elem, cnt in other.items(): result[elem] -= cnt Hopes this gives you some insight into the design choices. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: negative "counts" in collections.Counter?

2010-03-08 Thread Raymond Hettinger
[Steven D'Aprano] > Thanks for the explanation Raymond. A few comments follow: You're welcome :-) > Would you consider a feature enhancement adding an additional method, > analogous to update(), to perform subtractions? I recognise that it's > easy to subclass and do

Re: negative "counts" in collections.Counter?

2010-03-08 Thread Raymond Hettinger
[Vlastimil Brom] > Thank you very much for the exhaustive explanation Raymond! You're welcome. > I am by far not able to follow all of the mathematical background, but > even for zero-truncating multiset, I would expect the truncation on > input rather than on output of so

Re: negative "counts" in collections.Counter?

2010-03-08 Thread Raymond Hettinger
uld have slowed down the class, increased the code volume, and precluded some uses that are currently possible. IMO, that would not have been a win and it would not have helped the OP who was seeking a more vector-like tool for signed-number operations. Anyway, it is what it is. The tool is releas

Re: short-circuiting any/all ?

2010-03-22 Thread Raymond Hettinger
ter): from itertools import ifilter any(ifilter(is_invalid, L)) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Classes as namespaces?

2010-03-27 Thread Raymond Hettinger
On Mar 26, 7:49 am, kj wrote: > What's the word on using "classes as namespaces"?  E.g. > > class _cfg(object): >     spam = 1 >     jambon = 3 >     huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Works for me. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Binary Decimals in Python

2010-03-30 Thread Raymond Hettinger
. > > Is this by design? It seems to me that this is not the correct > behavior. The int() constructor returns integers. So, look to float() for non-integral values. Binary representation isn't supported yet, but we do have hex: >>> float.fromhex('1.8') 1.5 Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: sort array, apply rearrangement to second

2010-03-31 Thread Raymond Hettinger
es = ['A', 'B', 'C', 'D', 'E'] >>> keys = [50, 20, 40, 10, 30] >>> keyiter = iter(keys) >>> sorted(values, key=lambda k: next(keyiter)) ['D', 'B', 'E', 'C', 'A'] Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting ascending/descending with operator.attrgetter

2010-03-31 Thread Raymond Hettinger
en b, ascending)?" Rely on sort stability and do two passes: allmyfoos.sort(operator.attrgetter('b')) allmyfoos.sort(operator.attrgetter('a'), reverse=True) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: [RELEASED] Python 3.2 alpha 3

2010-11-16 Thread Raymond Hettinger
On Nov 16, 9:23 am, Mark Summerfield wrote: > I think it might be worth mentioning in What's New: FWIW, I'll be updating the What's New document for the Beta. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-24 Thread Raymond Hettinger
have their own initialization and finalization. If you guys know of good examples, I would appreciate a link or a recap. Thanks, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
On Nov 24, 9:16 pm, Alice Bevan–McGregor wrote: > On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > > > I'm writing-up more guidance on how to use super() and would like to > > point at some real-world Python examples of cooperative multiple > > inheritance

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
have enough control to just rename the methods to prevent name diamond shaped name clashes. OTOH, sometimes you don't have control over the names if they are magic methods or standard names like close(), save(), flush(), __init__(), etc. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
be called on multiple paths and each name should only be called exactly once. http://www.python.org/download/releases/2.2.3/descrintro/#cooperation Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Raymond Hettinger
ly and did try it for super(). However, you still need to drill into many of the hits manually, because it is difficult to disambiguate a single inheritance use of super() (which is very common) from a design with cooperative multiple inheritance. You have to read a lot of code and can still come up empty

Re: move to end, in Python 3.2 Really?

2011-01-17 Thread Raymond Hettinger
is similar (though it takes an index value instead of a boolean): >>> mylist.pop() # default case: pop from last >>> mylist.pop(0) # other case:pop from first Those were the design considerations. Sorry you didn't like the result. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: UTF-8 question from Dive into Python 3

2011-01-18 Thread Raymond Hettinger
2- If that were true, can you point me to some documentation about the > math that, as Mark says, demonstrates this? I believe Mark was referring to the bit-twiddling described in the Design section at http://en.wikipedia.org/wiki/UTF-8 . Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrappers in python

2011-01-27 Thread Raymond Hettinger
On Jan 27, 4:10 am, sl33k_ wrote: > What are wrappers? > >  What entities do they wrap around? > > Struggling to understand the concept. http://www.castle-cadenza.demon.co.uk/wrapper.htm Raymond -- http://mail.python.org/mailman/listinfo/python-list

Use the Source Luke

2011-01-28 Thread Raymond Hettinger
of you all seen other examples besides the Go language docs and the Python docs? Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Use the Source Luke

2011-01-28 Thread Raymond Hettinger
he replied "I'm not sure what you're asking - > do you want me to read the code aloud to you?"  So I just went and > read it. Thanks for the anecdote. I love that story :-) Uncle Timmy's style is both clever and pointed. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 29, 3:22 am, TP wrote: > On Fri, Jan 28, 2011 at 10:32 AM, Raymond Hettinger wrote: > > I hoping a new trend will start with dev's putting direct > > source code links in their documentation: > > >  http://rhettinger.wordpress.com/2011/01/28/open-your-sourc

Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 28, 3:10 pm, Ben Finney wrote: > Raymond Hettinger writes: > > The rest of the blame lies with installers. They all treat > > human-readable scripts like they were binaries and tuck the code away > > in a dark corner. > > That’s hardly a “blame” of installers

Re: Use the Source Luke

2011-01-31 Thread Raymond Hettinger
ore, so I'm still inclined to attribute the issue to 1) inconvenient placement of source code, 2) a largish code base, and 3) possibly a cultural shift. I'm thinking that all of those can be addressed by efforts to lower to intellectual investment required to find the relevant source cod

Re: IDLE: A cornicopia of mediocrity and obfuscation.

2011-02-01 Thread Raymond Hettinger
On Jan 31, 9:39 am, rantingrick wrote: > IDLE: cornucopia ... > These are just the top of the list. The peak of a huge iceberg that > threatens to sink the community in the arms of chaos never to return. That being said, I've taught a lot of people Python using IDLE. It's a surprisingly producti

An amazing one-minute bit of fun at the interactive prompt

2011-02-20 Thread Raymond Hettinger
>>> e = 10.0 ** -7; n = 0; z = c = complex(-0.75, e) >>> while abs(z) < 2.0: n += 1 z = z * z + c >>> n * e 3.1415926 Compute π ± e by counting Mandlebrot set iterations :-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: An amazing one-minute bit of fun at the interactive prompt

2011-02-20 Thread Raymond Hettinger
> Compute ð ± e by counting Mandlebrot set iterations :-) That should be: pi plus-or-minus e Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: An amazing one-minute bit of fun at the interactive prompt

2011-02-21 Thread Raymond Hettinger
On Feb 21, 12:08 am, Mark Dickinson wrote: > On Feb 20, 8:08 am, Raymond Hettinger wrote: > > > [...] > > >>> n * e > > > 3.1415926 > Very neat!  Is it supposed to be obvious why this gives an > approximation to pi?  If so, I'll think about it a

Re: Performance of list vs. set equality operations

2010-04-07 Thread Raymond Hettinger
immediately return unequal. If the two collections are unequal but have the same size, then the comparison time is data dependent (when the first mismatch is found). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Performance of list vs. set equality operations

2010-04-07 Thread Raymond Hettinger
[Raymond Hettinger] > > If the two collections have unequal sizes, then both ways immediately > > return unequal. [Steven D'Aprano] > Perhaps I'm misinterpreting what you are saying, but I can't confirm that > behaviour, at least not for subclasses of list: F

Re: Performance of list vs. set equality operations

2010-04-08 Thread Raymond Hettinger
that the case? Yes. Py_SIZE() gets the actual size of the underlying list. The methods for most builtin containers typically access the underlying structure directly. That makes them fast and allows them to maintain their internal invariants. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Performance of list vs. set equality operations

2010-04-09 Thread Raymond Hettinger
o influence the behavior of __eq__, then you're relying on an implementation detail, not the published interface. Eventhough the length check is an obvious optimization for list equality and set equality, there is no guarantee that other implementations of Python use that same pattern. my-two-cents-ly yours, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Tough sorting problem: or, I'm confusing myself

2010-04-11 Thread Raymond Hettinger
a heap. best2 = {} for i in itertools.combinations(range( 2**m), n-1): scorelist = [] for j in range( 2**m ): if j not in i: k = tuple(sorted(i + (j,))) scorelist.append((j, res[k][k.index(j)])) best2[i] = heapq.nlargest(2, scorelist, key=operator.itemgetter(1)) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Tough sorting problem: or, I'm confusing myself

2010-04-14 Thread Raymond Hettinger
oximate it with sampling random combinations (i.e. choose the best two scores out of 1 samples). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Tough sorting problem: or, I'm confusing myself

2010-04-14 Thread Raymond Hettinger
orm:  sorted(iterable)[:2]. > > I think you meant > >    sorted(iterable, reverse=True)[:2] :-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Raymond Hettinger
e to be private and that is what we already do with generator expressions. There's no RightAnswer(tm), just our best guess as to what is the most useful behavior for the most number of people. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: a.extend(b) better than a+=b ?

2010-04-22 Thread Raymond Hettinger
onstant difference is the overhead for making the call. The a.extend(b) does a dictionary lookup for the "extend" method and creates a bound method. Using a+=b is a little more direct. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Hi, friends. I wanna ask if there is a function which is able to take a list as argument and then return its top-k maximums?

2010-04-23 Thread Raymond Hettinger
On Apr 22, 10:49 am, John Nagle wrote: > Chris Rebert wrote: > > 2010/4/22 Jo Chan : > >> Hi,friends. > >>  I wanna ask if there is a function which is able to take a list as > >> argument > >> and then return its top-k maximums? > >> I only know about max which is poorly a top-1 maximum function

Re: Hi, friends. I wanna ask if there is a function which is able to take a list as argument and then return its top-k maximums?

2010-04-23 Thread Raymond Hettinger
terms of the basic minheap functions, but the underlying C code uses the same algorithm for both (using an underlying maxheap when necessary): http://svn.python.org/view/python/branches/py3k/Modules/_heapqmodule.c?revision=64351&view=markup Raymond -- http://mail.python.org/mailman/listinfo/python-list

Abstract attributes

2010-04-24 Thread Raymond Wynne
I was coding a simple abstract class for a database interface for a library I am writing. However, it occurred to me that you can't ask for a simple "abstract attribute", an attribute that is required for the class. Now, that could be implemented as a property, but a getter that merely returns a

Re: Deleting more than one element from a list

2010-04-25 Thread Raymond Hettinger
t; PLACEHOLDER = object() >>> for i in targets: ... z[i] = PLACEHOLDER >>> z[:] = [elem for elem in z if elem is not PLACEHOLDER] Here's another: >>> z=[45,12,96,33,66,'c',20,99] >>> targets = set([2, 3, 6]) >>> z[:] = [elem for i, elem in enumerate(z) if i not in targets] Besides being scaleable, these two examples have some nice learning points. Hopefully, you will find them useful. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: str.count algorithm

2010-05-04 Thread Raymond Hettinger
On May 4, 12:12 pm, Hellnar wrote: > Hello, > I am trying to find what algorithm Python uses for the built-in > str.count function, if it has a name. Roughly the same as: sum(1 for c in s if c == tgt) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension + lambdas - strange behaviour

2010-05-06 Thread Raymond Hettinger
er functions: >>> funs = [lambda x=x: x for x in range(5)] >>> [f() for f in funs] [0, 1, 2, 3, 4] Otherwise, the 'x' is just a global value and the lambdas look it up at when the function is invoked. Really, not surprising at all: >>> x = 10 >>> def f(): ... return x ... >>> x = 20 >>> f() 20 Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: an element from a set

2010-05-17 Thread Raymond Hettinger
next(iter(s)) or you can supply a default value in case the set is empty: x = next(iter(s), default_value) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: function that counts...

2010-05-24 Thread Raymond Hettinger
map=itertools.imap, int=int, str=str, range=range): return sum(m == sum(map(int, str(x))) for x in range(n)) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread Raymond Hettinger
; used, but with the ability to retrieve the first element where > bool(element) is True, which may be sometimes usefull. FWIW, it's not hard to roll your own fast itertools variants of any() and all(): next(ifilter(None, d), False) # first true, else False next(ifilterfals

Re: Is Scheme/LISP faster than C/C++

2010-06-14 Thread Raymond Toy
On 6/14/10 1:53 PM, fortunatus wrote: > For crying out loud, the best any compiler can do is make optimal > machine language. Many C compilers can do that over most inputs. So Is that why I had to use assembly code instead of C for some parts of my previous projects? There was even one example

Re: Why defaultdict?

2010-07-01 Thread Raymond Hettinger
ssing__() must be a method; it cannot be an instance variable. For an example, see collections.defaultdict.''' Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Python -- floating point arithmetic

2010-07-07 Thread Raymond Hettinger
028797018963968 -1/36028797018963968 1/2 18014398509481985/36028797018963968 -1/36028797018963968 5404319552844595/9007199254740992 21617278211378381/36028797018963968 -1/36028797018963968 3152519739159347/4503599627370496 25220157913274777/36028797018963968 -1/36028797018963968 720

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Raymond Hettinger
has been mutated in- place. Some other languages do it differently, but this is Guido's language, so we do it his way. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-24 Thread Raymond Hettinger
7;s __init__ but that method should only be called once (not once by B and again by C). In that case, the super() pattern shown above will let each parent's method be called exactly once and guarantee that parents are called before grandparents and guarantee that the left-to-right ordering of multiple bases is respected. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-25 Thread Raymond Hettinger
d a super() call or you can switch to an alternate design using composition instead of inheritance. Raymond P.S. Outside of the simple case of single inheritance, the one key to understanding super() is to forget about the concept of parent classes. Instead, super() is all about the MRO which is comp

Re: Compare two nested dictionaries

2010-07-25 Thread Raymond Hettinger
ot_second = s1 - s2 second_not_first = s2 - s1 difference_values = set(k for k in s1 & s2 if d1[k] != d2[k]) If the values are hashable, an alternate approach is: s1 = set(d1.items()) s2 = set(d2.items()) first_not_second = s1 - s2 second_not_first = s2 - s1 Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-26 Thread Raymond Hettinger
our diamond so that only one class inherits from object and that class doesn't use super(). Or you can wrap the super call in a try/except AttributeError. Cooperative multiple inheritance isn't pretty -- which is just another good reason to use composition rather that inherita

Re: Performance ordered dictionary vs normal dictionary

2010-07-29 Thread Raymond Hettinger
o, if you don't need the ordering feature, then you're better-off with a regular dictionary. A potential future implementation for OrderedDict written in C would have nearly identical performance as regular dicts for most operations and slightly improved performance for iteration

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Raymond Hettinger
On Jul 25, 5:30 pm, Gregory Ewing wrote: > Raymond Hettinger wrote: > > Every class > > in the MRO implementing the target method *must* call super() to give > > the next class in the MRO a chance to run. > > EXCEPT for the last one, which must NOT call super! > &

Re: shelf-like list?

2010-08-13 Thread Raymond Hettinger
On Aug 12, 1:37 pm, Thomas Jollans wrote: > On Tuesday 10 August 2010, it occurred to kj to exclaim: > > > I'm looking for a module that implements "persistent lists": objects > > that behave like lists except that all their elements are stored > > on disk.  IOW, the equivalent of "shelves", but f

Re: EXOR or symmetric difference for the Counter class

2010-08-14 Thread Raymond Hettinger
> I know how to > calculate it: > >     >>> b = Counter(a=1, b=2) >     >>> c = Counter(a=3, b=1) >     >>> diff = (b - c) + (c - b) > >>> diff > Counter({'a': 2, 'b': 1}) That seems simple enough. You could also use: diff = (b | c) - (b & c) # max(b,c) - min(b,c) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: random number generation

2010-08-16 Thread Raymond Hettinger
random.randint(0,2,size=[m,n]), but > I don't understand how to specify this proportion p. Try this: >>> from random import random >>> [1 if random() < 0.25 else 0 for i in range(20)] [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: EXOR or symmetric difference for the Counter class

2010-08-16 Thread Raymond Hettinger
subtract, but could possibly use multiply, divide, etc). Scaling operations are another possibility (multiple all elements by five, for example). The Counter() class has low aspirations. It is a dictionary that fills-in missing values with zero and is augmented by a handful of basic methods fo

q.join() is probably the wrong method for you

2010-08-18 Thread Raymond Hettinger
ll exist either when the tasks are done or when the timeout period has elapsed. Raymond > On Thursday, June 17, 2010 5:52 PM pacopyc wrote: > Hi, I am trying to work with threads and I need your help. This is > code: > > from threading import Thread > from Queue import Queue >

Re: Python Developer - HFT Trading firm - Chicago, IL

2010-08-21 Thread Raymond Hettinger
and crashes. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python-Dev] Released: Python 2.6.6

2010-08-24 Thread Raymond Hettinger
On Aug 24, 2010, at 12:31 PM, Barry Warsaw wrote: > Hello fellow Pythoneers and Pythonistas, > > I'm very happy to announce the release of Python 2.6.6. Thanks Barry :-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Making the case for repeat

2009-06-07 Thread Raymond Hettinger
or this style (and for the current design of itertools), look at the classic Hughes' paper "Why Functional Programming Matters". http://www.math.chalmers.se/~rjmh/Papers/whyfp.pdf Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: multi-core software

2009-06-07 Thread Raymond Wiker
Roedy Green writes: > On Fri, 5 Jun 2009 18:15:00 + (UTC), Kaz Kylheku > wrote, quoted or indirectly quoted someone who > said : > >>Even for problems where it appears trivial, there can be hidden >>issues, like false cache coherency communication where no actual >>sharing is taking place. O

Re: itertools.intersect?

2009-06-15 Thread Raymond Hettinger
ass streams = [sorted(sample(range(50), 30)) for i in range(3)] for s in streams: print(s) intersect(*streams) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: alternative to JoinableQueue's please

2009-06-26 Thread Raymond Hettinger
tasks.put(None) q.put(task) # doing work t = q.get() f(t) unfinished_tasks.get() # waiting for unfinished tasks to complete while unfinished_tasks.qsize(): sleep(0.1) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Raymond Hettinger
of trees (red-black, pairing heaps, etc). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Raymond Hettinger
nd popping; and O(n) iteration. The ASPN Cookbook has equivalent code that runs on earlier versions of Python. > in Python. And I really enjoy the using this language. Am glad you like it. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: finding most common elements between thousands of multiple arrays.

2009-07-08 Thread Raymond Hettinger
and later, see heapq.nlargest(). In Py3.1, see collections.Counter(data).most_common(n) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
ing cases, the switchover point from heapq to sorted needs a programmer's judgment based on whether the input iterable has a known length, the cost of comparison function, and whether input is already partially ordered. The advice in the docs helps the reader understand the relationships between min, max, nsmallest, nlargest, and sorted. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
table for looping. While nothing in the list/tuple code requires you to make that distinction, it is important because that philosophy pervades the language. If you follow Guido's direction, you'll find that the various parts of the language fit together better. Do otherwise and you

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
his minions (me included) have designed the APIs and optimizations to flow nicely with his preferred way of doing things. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-31 Thread Raymond Hettinger
way (perhaps to use it as a key for dict or set in a caching function) or because something unfroze it (so it could mutate a value). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: heapq "key" arguments

2009-08-03 Thread Raymond Hettinger
nsmallest documentation says: > >         Equivalent to: sorted(iterable, key=key)[:n] Yes. The code for nsmallest and nlargest preserves stability so that the equivalence is maintained. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: heapq "key" arguments

2009-08-03 Thread Raymond Hettinger
ry')). The flexibility to change key functions just doesn't make sense in the context of the fine-grained heap functions. Accordingly, this is why I put key functions in nlargest() and nsmallest() but not in heappush() and friends. The former can guarantee no more than one key functio

Re: no-clobber dicts?

2009-08-04 Thread Raymond Hettinger
In general, if a subclass is overriding, rather than extending, then it should override *every* method that could be affected. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Subclassing Python's dict

2009-08-06 Thread Raymond Hettinger
> Are you referring to Python 3.0?  Python 2.6 does not have > collections.UserDict In Python2.6, it is in its own module. >>> from UserDict import UserDict Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Subclassing Python's dict

2009-08-06 Thread Raymond Hettinger
, there are still some cases of UserDict being used in the python source (situations where subclassing from dict wouldn't work as well). Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Python docs disappointing - group effort to hire writers?

2009-08-11 Thread Raymond Hettinger
isting tutorial's > intended audience. There is more than one right answer to "what is the best tutorial for different people". The www.python.org website lists a number of tutorials. Here is the page specifically marked for those who are new to programming: http://wiki.pytho

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

2009-08-12 Thread Raymond Hettinger
rytime someone writes a buggy program. In short, most doc requests that get rejected are requests that didn't actually improve the documentation. I do support links from the regular docs to an external wiki but the main docs should continue to go through the regular process using the tracker. Raymond -- http://mail.python.org/mailman/listinfo/python-list

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

2009-08-12 Thread Raymond Hettinger
with a fuller discussion on the art of sorting including a discussion of operator.itemgetter() and operator.attrgetter() which were designed to work with the key= parameter. Raymond -- http://mail.python.org/mailman/listinfo/python-list

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

2009-08-12 Thread Raymond Hettinger
[Raymond Hettinger] > Here are a few thoughts on list.sort() for those who are interested: After one more reading of Xah Lee's posts on the documentation for sort, here are couple more thoughts: * The reason that list.sort() allows None for the cmp parameter is not so that you c

Re: implementing descriptors

2009-08-13 Thread Raymond Hettinger
start: self._end = value else: self._start = value end = property(get_end, set_end) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: implementing descriptors

2009-08-15 Thread Raymond Hettinger
> Raymond, >    This functionality is exactly what I was looking for. Thanks!  I'll > be using this to solve my problem. > >    Now that I'm on the right track, I'm still a bit confused about how > __get__ and __set__ are useful.  Admittedly, I don't need to &

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

2009-08-16 Thread Raymond Hettinger
, there is a recipe for expanding the comparison operators: http://code.activestate.com/recipes/576685/ Raymond -- http://mail.python.org/mailman/listinfo/python-list

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

2009-08-17 Thread Raymond Hettinger
t is a fair criticism of Python's compiler that it does not do much in the way of optimizations. It does a handful of basic peephole optimizations but that is about it. Other languages like Haskell fair better in this regard. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: #elements of seq A in seq B

2009-08-20 Thread Raymond Hettinger
v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import collections >>> A = 'abc' >>> B = 'abracadabra' >>> collections.Counter(filter(A.__contains__, B)) Counter({'a': 5, 'b': 2, 'c': 1}) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: #elements of seq A in seq B

2009-08-20 Thread Raymond Hettinger
v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import collections >>> A = 'abc' >>> B = 'abracadabra' >>> collections.Counter(filter(set(A).__contains__, B)) Counter({'a': 5, 'b': 2, 'c': 1}) Raymond -- http://mail.python.org/mailman/listinfo/python-list

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

2009-09-02 Thread Raymond Hettinger
ard deviation when you're the one generating data). ISTM, there ought to be a statistics module that can calculate cumulative distribution functions for a variety of distributions. This would be far more helpful than creating more generators. Raymond -- http://mail.python.org/mailman/listinfo/python-list

<    3   4   5   6   7   8   9   >