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

标签 python jython sorting

我无法在我正在使用的机器上使用旧版本 (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/

相关文章:

java - 从 java 执行 Jython 脚本并获取结果

python - 从数组中删除随机选择的元素

silverlight - 如何在 Silverlight 中使用 Telerik RadGridView 将列设置为默认排序列

python - Django模型继承: create sub-instance of existing instance (downcast)?

python - 从文件夹中的现有 jar 创建类路径

python - 在 model.fit() 期间记录 Keras 中每个时期的计算时间

python - 如何让 emacs 在确定打开文件的模式时忽略 shebang (#!/some/interpreter)

java - Jython 作为 Java 游戏的游戏内控制台

python - SublimeREPL 到 python

iOS NSFetchedResultsController : sort sections by >=2 properties