Random Python Questions #1

What is the result of the below Python code:

from collections import Counter
input_dictionary = {‘a’:5, ‘b’:3, ‘c’: 1, ‘b’:2}
print(Counter(input_dictionary))

Result:
Counter({‘a’: 5,
‘b’: 2, ‘c’: 1})

Question:

Even-though we have 2 values for the key ‘b’ in “input_dictionary”, the result has only one ‘b’ key/value pair. Do you know why? What’s the reason?

Leave a comment

Design a site like this with WordPress.com
Get started