a small problem

Thomas Wouters thomas at xs4all.net
Thu Jan 13 07:05:14 EST 2000


On Wed, Jan 12, 2000 at 04:59:32PM +0100, Gerrit Holl wrote:

> People should hang around in comp.lang.c or even comp.lang.asm.i386 if
> they care about speed.

No, they should be there if they _only_ care about speed. 

> > On the other hand, oneliners will always feel or look faster to some people.

Well, after saying that, and the dutch railways involuntarily extended my
travelling from 2 hours to 4 1/2, i tried it out, in the train, on my PII-233
laptop. The reduce() of the original problem took half again as long as the
for loop tim proposed. the map/reduce i suggested took a notch longer than
that. I wont be using lambda's and think of speed at the same time, from now
on ;)

Another amusing thing was that I wrote:

for x, in mylist:

to iter over the testlist (a list of single-item tuples.) I didn't
consciously think about it, but when i reread it, i decided it couldn't be
right. It would just be too obvious. There had to be a reason for it to be a
special case of some kind, like perl has with the magic ++ operator on
strings. Contrary to the string-++ operator in perl, though, it worked just
as expected ;)

(Maybe someone here can explain the perl weirdness to me. "string"++ in perl
works only on strings that match the pattern '^[a-zA-Z]*[0-9]*$'. A
colleague wrote some code that searched for "<prefix><number>", where prefix
only allowed [a-z] and number [0-9]. He used ++ to go from number 0 on up.
Some months ago, someone changed the prefix limit to [a-z0-9], and last week
someone actually tried to use prefix 'pop2h'. And 'pop2h001'++ yielded 1,
breaking numerous things in mysterious ways. But, _why_ is the ++ operator
limited in such an artificial way ? The local perl gurus refuse to answer me
;)

<snip>
> How would I do that without lambda's, if this code is in a method? Should
> I nest two functions?

For a straight translation without lambda's you can _always_ use functions.
nested, if you wish, but not necessarily. lambda's work _exactly_ like
nested functions, only you cant use statements in them, only expressions.

But doing it without lambda is not the point -- if lambda wasn't there,
there would possibly be a more convenient way to do such things, or even
more speedy (like a module of functions, like operator, for use with map.
basic things like adding the first element of each argument. Or something.)

<snip>
> lambda's are good, because otherwise, it wouldn't be possible to write
> obfuscated code in Python... Can someone please rewrite the one-liner

You're missing the point. Guido does not believe obfuscated code is good.
Why would Python need obfuscated code ? It goes through great pains(*), in
fact, to make obfuscated code very hard.

(*)Admittedly mostly other peoples' pains, the ones who dislike forcefed
indentation, for instance :)

> > Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
> Oh, help! My computer is infected! What should I do now?!

The usual cure is to install a less gullible mind, or indeed, any at all.
But that is what the signature tries to do, so perhaps you can consider
yourself cured ;)

Conspirationally-y'rs, 
-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list