Python 在Jython中使用OrderedDict

Python 在Jython中使用OrderedDict,python,iteration,jython,ordereddictionary,Python,Iteration,Jython,Ordereddictionary,我想在Jython用一台定购的ICT。当我用Python编写它时,它工作得很好;但是,当我尝试使用Jython编写相同的代码时,它给出了一个Java错误(我还让它说collections模块没有OrderedDict属性)。模块错误如下所示: ERROR: Exception (main): 'module' object has no attribute 'OrderedDict' 所以我要做的是按照字典中的值被输入的相同顺序输出它们。我想在Jython中创建以下功能(用Python编写):

我想在Jython用一台定购的ICT。当我用Python编写它时,它工作得很好;但是,当我尝试使用Jython编写相同的代码时,它给出了一个Java错误(我还让它说collections模块没有OrderedDict属性)。模块错误如下所示:

ERROR: Exception (main): 'module' object has no attribute 'OrderedDict'
所以我要做的是按照字典中的值被输入的相同顺序输出它们。我想在Jython中创建以下功能(用Python编写):

import collections

example = collections.OrderedDict()

example["c"] = 3
example["b"] = 4
example["d"] = 3
example["e"] = 9
example["a"] = 7

for key, value in example.iteritems():
    print key + ": " + str(value)
这将导致:

c: 3
b: 4
d: 3
e: 9
a: 7
现在我假设这对我在Jython不起作用的原因是因为OrderedDict不存在于其中。说到这里,Jython有没有办法做到这一点?也许它需要Java代码

编辑:

我找到了一种使用列表和元组的方法,如下所示:

example = []

example.append(("c", 3))
example.append(("b", 4))
example.append(("d", 3))
example.append(("e", 9))
example.append(("a", 7))

for tup in example:
    key, value = tup
    print key + ": " + str(value)

虽然这样做有效,但我仍然想知道如何使用字典。

如果您需要
集合。OrderedICT
,您必须使用Jython 2.7版或更高版本,因为Python中没有引入
集合。OrderedICT

您的问题应该包括您看到的错误。我猜您看到的是这样的:
AttributeError:'module'对象没有属性'orderedict'
正确,抱歉-添加了ithmm。嗯,我使用的是Sikuli(使用Jython),很明显它在摇摆Jython-2.1。。。。。。。。。。