我无法在我正在使用的机器上使用旧版本 (2.2.1) 的 Jython,但我需要 sorted 方法。我已经从 future 导入了生成器,但是
from __future__ import sorted
返回 SyntaxError:未定义 future 排序的特征。有没有我可以导入的模块?
最佳答案
如果您受困于旧版本的 jython,也许您应该改用 .sort()
?
>>> a = [ 3, 1, 4, 1, 5, 9 ]
>>> a.sort()
>>> a
[1, 1, 3, 4, 5, 9]
您甚至可以定义自己的排序来替换丢失的:
>>> 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]
关于python - 我可以在 Jython 中使用 from __future__ 导入排序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855567/