very good reasons?
François Pinard
pinard at iro.umontreal.ca
Sun Oct 1 11:47:10 EDT 2000
> [Grant Griffin]
> >I would have expected sort and reverse to return the list in question,
> >but instead they return None. So I had to do something like:
[Kragen Sitaker]
> If you want Perl, you know where to find it: in Python! Here's how:
> def sort(x):
> y = list(x)
> y.sort()
> return y
> def reverse(x):
> y = list(x)
> y.reverse()
> return y
I'm not sure that `y = list(x)' returns `y' different than `x', if `x' is
already a list, in which case the functions above would mutate operands,
which is not welcome. Maybe (?) it would be safer to write:
def sort(x):
y = x[:]
y.sort()
return y
def reverse(x):
y = x[:]
y.reverse()
return y
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list