Ska*_*One 5 python ordereddictionary python-3.x
我将如何在特定位置(从 0 开始)更新 OrderedDict 的值?所以:
od = OrderedDict(a=1, b=2, c=3)
od.update({'b': 4}) # a=1, b=4, c=3
od.update_values(2, 1) # a=2, b=1, c=3
Run Code Online (Sandbox Code Playgroud)
小智 5
这很简单 - 只需使用od[od.keys()[x]] = y
这也适用于字典(尽管这毫无意义)。代码只是获取listorderedDict 的一个键,然后从列表中获取所需位置的条目,然后使用该字符串作为原始orderedDict 的键。