我可以在Jython中使用__future__导入使用排序吗?

Cli*_*der 4 python jython sorted

我在正在使用的计算机上使用Jython的较旧版本(2.2.1),但我需要排序的方法。我已经从未来导入了发电机,但是

from __future__ import sorted
Run Code Online (Sandbox Code Playgroud)

返回SyntaxError:未定义将来的功能。有可以导入的模块吗?

ram*_*ion 5

如果您坚持使用旧版本的jython,也许应该.sort()改用?

>>> a = [ 3, 1, 4, 1, 5, 9 ]
>>> a.sort()
>>> a
[1, 1, 3, 4, 5, 9]
Run Code Online (Sandbox Code Playgroud)

您甚至可以定义自己的排序来替换缺少的排序:

>>> 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]
Run Code Online (Sandbox Code Playgroud)