Simplified ListMixin.sort().

This commit is contained in:
Sergey Fedoseev 2018-09-17 19:54:37 +05:00 committed by Tim Graham
parent 583b9fc410
commit 4441778c26
1 changed files with 2 additions and 12 deletions

View File

@ -210,19 +210,9 @@ class ListMixin:
"Standard list reverse method"
self[:] = self[-1::-1]
def sort(self, cmp=None, key=None, reverse=False):
def sort(self, key=None, reverse=False):
"Standard list sort method"
if key:
temp = [(key(v), v) for v in self]
temp.sort(key=lambda x: x[0], reverse=reverse)
self[:] = [v[1] for v in temp]
else:
temp = list(self)
if cmp is not None:
temp.sort(cmp=cmp, reverse=reverse)
else:
temp.sort(reverse=reverse)
self[:] = temp
self[:] = sorted(self, key=key, reverse=reverse)
# ### Private routines ###
def _rebuild(self, newLen, newItems):