From b58ba323f474ab0b54a9a5dee9b89c0c99e437e1 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 14 Aug 2009 16:58:47 +0200 Subject: [PATCH] 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. --- src/compat/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/compat/__init__.py 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 -- 2.30.2