Only add sorted if < 2.4.0

This commit is contained in:
Jeremy Fincher 2004-12-02 05:34:12 +00:00
parent f7a3504a93
commit 3904672c2f

View File

@ -431,18 +431,19 @@ def sortBy(f, L):
for (i, elt) in enumerate(L): for (i, elt) in enumerate(L):
L[i] = L[i][2] L[i] = L[i][2]
def sorted(iterable, cmp=None, key=None, reversed=False): if sys.version_info < (2, 4, 0):
L = list(iterable) def sorted(iterable, cmp=None, key=None, reversed=False):
if key is not None: L = list(iterable)
assert cmp is None, 'Can\'t use both cmp and key.' if key is not None:
sortBy(key, L) assert cmp is None, 'Can\'t use both cmp and key.'
else: sortBy(key, L)
L.sort(cmp) else:
if reversed: L.sort(cmp)
L.reverse() if reversed:
return L L.reverse()
return L
__builtins__['sorted'] = sorted __builtins__['sorted'] = sorted
def mktemp(suffix=''): def mktemp(suffix=''):
"""Gives a decent random string, suitable for a filename.""" """Gives a decent random string, suitable for a filename."""