Reputation: 43
I have this code:
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))
But when I run the program, I get this:
defaultdict(<function last3scores at 0x0000000003806E18>, {'nick': deque([2], maxlen=3)})
What I'd like to get is this:
{'nick': [2]}
Is there a way to accomplish that in Python 3.* ?
Upvotes: 3
Views: 11768
Reputation: 15320
This should do the trick (in Python 3.* switch to items
instead of iteritems
):
>>> {k:list(v) for k,v in user_last3.iteritems()}
{'nick': [2]}
Upvotes: 1
Reputation: 511
Maybe you can try following:
for key, value in user_last3.iteritems():
print key, value
Upvotes: 0