From: Matthijs Kooijman Date: Fri, 14 Aug 2009 14:58:47 +0000 (+0200) Subject: Add compat module with a sorted function. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fmobilegtd.git;a=commitdiff_plain;h=b58ba323f474ab0b54a9a5dee9b89c0c99e437e1 Add compat module with a sorted function. The sorted builtin function was not available in python 2.2 yet (pys60 1.4.x), so we add our own version. --- diff --git a/src/compat/__init__.py b/src/compat/__init__.py new file mode 100644 index 0000000..e9ff884 --- /dev/null +++ b/src/compat/__init__.py @@ -0,0 +1,17 @@ +import sys + +# sorted() was introduced in 2.4 +if sys.version_info[:2] < (2, 4): + # Define our own version of sorted + def sorted(iterable, cmp=cmp, key=lambda x: x, reverse = False): + # Make a list out of the iterable + lst = list(iterable) + # Sort the list, using the given comparator and key function + lst.sort(lambda x, y: cmp(key(x), key(y))) + # Reverse if requested + if reverse: + lst.reverse() + # Done! + return lst +else: + sorted = sorted