python SortedDict 遍历删除 不对
Posted 软件工程小施同学
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python SortedDict 遍历删除 不对相关的知识,希望对你有一定的参考价值。
topLevel = SortedDict(neg) # 从大到小排序
for priority, Id in topLevel.items():
print("topLevel1", topLevel)
# # 将Id从topLevel中删除
topLevel.pop(priority)
print("topLevel2", self.Txpool.topLevel)
发现4000011: 11没有遍历就跳出了
![](https://image.cha138.com/20230302/de0c31c3cb704a58bf74f04d582d0fc8.jpg)
修改后
tmp = [(k,v) for k,v in topLevel.items()]
print(len(tmp))
for priority, Id in tmp:
print("topLevel1", topLevel)
# # 将Id从topLevel中删除
topLevel.pop(priority)
print("topLevel2", self.Txpool.topLevel)
![](https://image.cha138.com/20230302/1cc38fc9accc4ffc835de4217b8be8ba.jpg)
以上是关于python SortedDict 遍历删除 不对的主要内容,如果未能解决你的问题,请参考以下文章