Python vs. Ruby
Justin Shaw
wyojustin at hotmail.com
Tue Dec 31 22:54:03 EST 2002
> * breaking object-orientation to return new objects when sorting
> sequences ;)
<snip>
> o might also want to explain that it's not a hard thing to fix
> at some point in Python (if the powers-that-be want to) by
> adding "sorted" and "reversed" methods to the list object
> (no clue why you want "append" to create a new list, sounds
> silly to me ;) ).
You don't have to return a "new" list. What is non-object oriented about
this?
>>> class List(list):
def sort(self):
list.sort(self)
return self
def append(self, item):
list.append(self, item)
return self
>>> l = List([3, 2, 1])
>>> l.append(5).sort()
[1, 2, 3, 5]
More information about the Python-list
mailing list