Is it possible to import sorted with __future__ into Jython?
I am stuck using the old version (2.2.1) of Jython on the machines I am working on, but I need a sorted method. I am already importing generators from the future , but
from __future__ import sorted
returns SyntaxError: the sorting of the future function is undefined. Is there a module I can import that has it?
+3
source to share
1 answer
If you're stuck with an older version of jython, maybe you should use .sort()
instead?
>>> a = [ 3, 1, 4, 1, 5, 9 ]
>>> a.sort()
>>> a
[1, 1, 3, 4, 5, 9]
You can even define your own to replace the missing one:
>>> def my_sorted(a):
... a = list(a)
... a.sort()
... return a
...
>>> b = [3,1,4,1,5,9]
>>> my_sorted(b)
[1, 1, 3, 4, 5, 9]
>>> b
[3, 1, 4, 1, 5, 9]
+4
source to share