我有这个代码:
import collections
def last3scores():
return collections.deque([], 3)
user_last3 = collections.defaultdict(last3scores)
#after this I have some more code and then this:
user_last3[name].append(score)
print(str(user_last3))
但是当我运行程序时,我得到了这个:
defaultdict(<function last3scores at 0x0000000003806E18>, {'nick': deque([2], maxlen=3)})
我想得到的是:
{'nick': [2]}
有没有办法在 Python 3.* 中实现这一点?
最佳答案
这应该可以解决问题(在 Python 3.* 中切换到 items
而不是 iteritems
):
>>> {k:list(v) for k,v in user_last3.iteritems()}
{'nick': [2]}
关于python - 如何在双端队列中打印项目(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35153766/