Thoughts about Python
Marco Aschwanden
PPNTWIMBXFFC at spammotel.com
Wed Feb 25 05:18:54 EST 2004
> 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:
>>> lst = []
>>> lst.append(3)
>>> lst.sort()
>>> lst.reverse()
>>> count = len(lst)
The last line looks a bit odd after all the dot-notations to see a
function-call in the last line.
> 4_ If the python interpreter was smart enough sort()
> [...]
> Inmutable types are usually less "magical" than their
> mutable counterpart.
>
> For instance:
>
> >>> lst1=[1,2]
> >>> lst2=lst1
> >>> lst2.append(3)
> >>> lst1
> [1, 2, 3]
> >>> lst2
> [1, 2, 3]
> >>> tup1=(1,2)
> >>> tup2=tup1
> >>> tup2=tup2+(3,)
> >>> tup1
> (1, 2)
> >>> tup2
> (1, 2, 3)
> >>>
>
> Do you think a newbie would expect that a modification
> on one variable would have a effect on another?
Good point.
Thanx,
Marco
More information about the Python-list
mailing list