Add list.sorted() classmethod.

This commit is contained in:
Raymond Hettinger 2003-10-29 06:54:43 +00:00
parent c43a7e7c37
commit 0a9b9da0c3
5 changed files with 113 additions and 6 deletions

View file

@ -78,6 +78,11 @@ class UserList:
def index(self, item, *args): return self.data.index(item, *args)
def reverse(self): self.data.reverse()
def sort(self, *args, **kwds): self.data.sort(*args, **kwds)
def sorted(cls, iterable, *args, **kwds):
s = cls(iterable)
s.sort(*args, **kwds)
return s
sorted = classmethod(sorted)
def extend(self, other):
if isinstance(other, UserList):
self.data.extend(other.data)