【问题标题】:Python duplicate keys, cannot find keys in dictPython重复键,在dict中找不到键
【发布时间】:2013-07-26 18:58:46
【问题描述】:

伙计们,这很奇怪,可能是我没有看到的一些小错误:

所以我有一个带有键作为元组的字典。每个键都是(状态,动作)的元组,其中状态是包含值和元组的元组。行动是一种价值。

我正在从文件中加载我的字典并且它正确加载。在程序期间的某个时刻,它会检查密钥是否存在。如果是,则更改值,否则创建 dict[key] = 0。

问题是这样的:字典有一个具有特定值的键(状态、动作)。当我尝试使用“in”检查它是否存在时,它表明它不存在。当我检查 dict.keys() 时,它声明它存在。我还输出了 dict.keys() 并且可以验证它确实存在。

此外,如果我将值与其他值(例如:dict[key] > secondValue)进行比较,程序会崩溃。如果我做 dict[key] = secondValue,有时它不会改变键的值,而是创建一个重复的键!然后, dict.keys() 返回两个或多个相同的键。这是一些代码:

    if (key not in self.currentDict):
                pass
                print "key not in self.currentDict"
                if key not in self.currentDict.keys():
                    print "key not in self.currentDict.keys()"
                else:
                    print "key in self.currentDict.keys()"

上述缩进不是错误,实际代码中缩进是可以的。

现在这些中的每一个都会使程序崩溃:

print "self.currentDict[key] = %s" % (self.currentDict[key])
if (self.currentDict[key] > value)

我真的不知道为什么会这样。如果我启动一个新文件,程序运行并保存到文件中,它可以正常工作。如果我使用现有文件,因此使用现有字典,它要么崩溃,要么创建键的重复项(许多消息来源指出这是不可能的)。

有什么想法吗?谢谢!

--编辑--

pass 只在打印之前存在,对结果没有影响

这是我从程序中得到的最后一个输出。很抱歉字典键很长!

key not in self.currentDict

key in self.currentDict.keys()

key not in self.currentDict

self.currentDict = {
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.5): 0, 
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.6): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.7): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.7): -88.0, 
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.2): -96.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.6): -168.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.1): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.5): -91.2,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.8): -102.39999999999999,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.7): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.3): -113.6,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.2): -80.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.1): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.3): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.5): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.6): -96.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.8): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.4): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.4): -80.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.8): -104.8030982226376,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.8): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.1): -120.0, # <---------------
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.2): -96.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.5): -97.6,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.2): -96.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.4): -120.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.3): -107.19999999999999,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.6): -88.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.7): -96.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.4): -104.0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.1): 0,
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.3): -88.0}

self.currentDict.keys() = [
     (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.5),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.6),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.7),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.7),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.2),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.6),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.1),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.5),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.8),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.7),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.3),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.2),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.1),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.3),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.5),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.6),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.8),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.4),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.4),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.8),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.8),
      (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.1), # <-----------
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.2),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.5),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.2),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.4),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.3),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.6),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.7),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.4),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.1),
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.3)]

与

key = (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.1)

self.currentDict 的类型 = &lt;type 'dict'&gt;

我通过从文件中加载字典字典并将最后一个字典深度复制到 self.currentDict 来获取 self.currentDict。

我也执行了这段代码:

    keyProblems = [k for k in self.currentDict.keys() if k not in self.currentDict]
    print "keys with problems: %s" %(str(keyProblems))

返回了这个结果:

    keys with problems: 
    [(((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.6), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.7), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.7), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.2), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.6), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.1), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.8), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.7), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.3), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.2), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.1), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.3), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.6), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.8), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.4), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.4), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.8), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.8), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 1.1), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.2), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.2), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.4), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.3), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.6), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.7), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 3.4), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 4.1), 
    (((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)), 2.3)]

澄清一下,上面的所有值(包括动作)都是离散的(没有重复的浮动)

将问题隔离在两个方法调用之间。这些方法是从应用程序中按顺序调用的。在第一种方法结束时,没有出现问题的键。第二种方法一开始,很多key都有问题(按照上面的代码)。现在的问题比以前更加神秘:/

更新:我在另一台笔记本电脑上测试了相同的程序,令人惊讶的是,即使运行了数十次,它也能完美运行,没有任何“关键问题”。这些是每台笔记本电脑上的配置:

笔记本电脑 1:

    Windows 7 Home Premium Service Pack 1, 64-bit, i7-3610QM, 8GB RAM
    Running under Eclipse with PyDev, application's internal Python: Crashes + key problems
    Running directly from .bat file and outside Eclipse/Pydev, Pydev still installed: Crashes + key problems
    Running under Eclipse with Pydev, using Python 2.7 installed in drive C: Crashes + key problems
    Running directly from .bat file and outside Eclipse/Pydev, Pydev uninstalled: Crashes + key problems

笔记本电脑 2:

    Windows 7 Ultimate Service Pack 1, 64-bit, Dual Core T5550, 4GB RAM
    Pydev: Did not manage to test it with Pydev without having import errors
    Running directly from .bat file and outside Eclipse/Pydev, Pydev installed: Works correctly even after tens of runs, list of key problems always empty

我正在为两台笔记本电脑使用项目目录的精确副本和相同的路径。对可能发生的事情有任何想法吗?

【问题讨论】:

  • 请张贴字典(或样本,如果它太小)和您正在检查的钥匙
  • 它是否与您正在读取的文件中的行终止有关 - 这些东西可能很挑剔(CR vs CRLF vs LF,取决于操作系统)。这不是第一次导致难以跟踪的问题。尝试将字符串转储为十六进制。
  • @inspectorG4dget 刚刚发布了字典 :)
  • 我的眼睛受伤了。请添加一些格式到 dict
  • @inspectorG4dget 为未找到的键(也在 self.currentDict.keys() 中)添加了粗体格式

标签: python dictionary key duplicates tuples


【解决方案1】:

我认为您认为self.currentDict 和self.currentDict keys 之间存在差异...并且不知何故,第一个给您元组的第一个元素,第二个给您第二个...

检查元组是否作为键存在:

if ('state', 'value') in self.currentDict

要分配,你应该这样做:

self.currentDict[('state', 'value')] = 'some value'

(注意:括号不是绝对必要的,但恕我直言更清楚)

【讨论】:

  • 我将键构建为元组,因此: stateTuple = 将状态从列表转换为元组 action = action value key = (stateTuple, action)
  • 刚刚尝试做 (self.currentDict[(stateTuple, action)] > value) 但仍然遇到同样的崩溃:/
  • @user2623934 详细说明崩溃...将错误/回溯复制并粘贴到您的问题中
  • 真的不能...我正在构建一个程序的扩展,该程序内置了没有任何文档的 python 2.7,所以我得到的只是“此应用程序已请求运行时以不寻常的方式。” @乔恩克莱门茨
  • @user2623934 这是您应该在问题中提供的信息...以及清理和格式化您的字典 - 请记住它只需要几行作为示例...
猜你喜欢
  • 1970-01-01
  • 2018-04-08
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 2018-10-12
  • 1970-01-01
  • 2011-03-25
相关资源
最近更新 更多