diff options
author | Robert Brewer <fumanchu@aminus.org> | 2009-06-15 00:00:12 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2009-06-15 00:00:12 +0000 |
commit | ffdf13c8217f3a785fe8768697b3e3da4b6ff9cb (patch) | |
tree | 22ef192538d1e7dd5793852f13d91527f6dbe7eb /cherrypy/py3util.py | |
parent | 4cf7b94cd1b78da25518552b976a8879f2f7ffe4 (diff) | |
download | cherrypy-git-ffdf13c8217f3a785fe8768697b3e3da4b6ff9cb.tar.gz |
Use builtin sorted, reversed if available.
Diffstat (limited to 'cherrypy/py3util.py')
-rw-r--r-- | cherrypy/py3util.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/cherrypy/py3util.py b/cherrypy/py3util.py index ed722dba..afa4c840 100644 --- a/cherrypy/py3util.py +++ b/cherrypy/py3util.py @@ -3,11 +3,17 @@ A simple module that helps unify the code between a python2 and python3 library. """ import sys -def sorted(lst): - newlst = list(lst) - newlst.sort() - return newlst +try: + sorted = sorted +except NameError: + def sorted(lst): + newlst = list(lst) + newlst.sort() + return newlst -def reversed(lst): - newlst = list(lst) - return iter(newlst[::-1]) +try: + reversed = reversed +except NameError: + def reversed(lst): + newlst = list(lst) + return iter(newlst[::-1]) |