Python Forum

Full Version: Dictionary Methods
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I just wanted to know if there is a way to count the individual keys in a dictionary and print the amount of times they appear.
Lets say you have a dictionary named mydict, then
print(len(mydict.keys()))
or
print(len(mydict))
>>> zz = {'a':123, 'b':456, 'c':789}
>>> len(zz)
3
I think each key can appear only once in a standard dict. A standard dict doesn't permit key duplication.