It feels so good, so quick and not C!
staschuk at telusplanet.net
Wed Mar 19 06:19:08 CET 2003
Quoth John Machin:
> Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1047969613.29891.python-list at python.org>...
[...a strrev implementation...]
> > If you're just learning Python, you might want to spend a few
> > minutes studying this version. It has one slightly subtle point
> > for which I would write a comment if this were real code.)
> Which if any of the following "subtle" points did you mean? (1)
> "backwards" is as twice as large as it needs to be, with the unwanted
> guff jettisoned by zip(). [...]
That's the one, more or less.
Imho exploiting this behaviour of zip deserves the word subtle,
without scare quotes, for a Python newcomer. The point, of
course, is that the backwards range can be written more clearly
> [...] (2) "forwards", "backwards", and the zip()
> result constitute about (3 * len(orig)) objects clogging up memory.
*shrug* So use xrange and izip.
> (3) The cuteness of swapping by "x, y = y, x" hides the overhead of
> packing and unpacking a 2-tuple, which may or may not be faster than
> the traditional 3-assignment method.
I confess a weakness for the cute swapping method; on my machine
it is, in fact, perhaps 5% slower. I don't usually worry about it.
Steven Taschuk staschuk at telusplanet.net
Receive them ignorant; dispatch them confused. (Weschler's Teaching Motto)
More information about the Python-list