Thoughts about Python
Bob Ippolito
bob at redivi.com
Thu Feb 26 03:40:04 EST 2004
On 2004-02-25 05:18:54 -0500, PPNTWIMBXFFC at spammotel.com (Marco
Aschwanden) said:
>> I agree with you in all but that tuples are not
>> necessary. Lists are the ones that are actually a
>> hack for speed! :-)
>
> Did you do some time profiling? I would be interested in the results.
>
>
>> 3_ I prefer reading from left to right instead from right
>> to left (it makes the parenthesis less confusing too).
>> Compare to:
>>
>> count=len(reversed(sorted(appended(lst,3)))).
>>
>> Maybe I should learn Hebrew :-)
>> Or we could always change it to
>>
>> $ lst|append -3|sort|reverse|len
>>
>> (in the end all are just filter patterns :))
>
> This is an excellent example!
> count = lst.append(3).sort().reverse().len()
> is extremly readable but chaining of method calls is not supported in
> Python. And I can live with it... Python has a more "expressive" path:
You can 'chain method calls' all you want.. what you're missing here is
a python idiom: methods that mutate an object shall not return the
same object.
If the above code were to actually work, then "lst" would contain an
extra element and be stored in reverse sorted order, while "count"
would be the number you were trying to extract. The intent probably
was not to modify "lst", so this particular idiom just saved you the
time of debugging your broken code by encouraging you to do it the
right way the first time.
-bob
More information about the Python-list
mailing list