Answers for "how to get the number of keys in a dictionary python"

5

how to get the key for a value in a dictionary in python

# function to return key for any value 
def get_key(val): 
    for key, value in my_dict.items(): 
         if val == value: 
             return key 
  
    return "key doesn't exist"
  
# Driver Code 
  
my_dict ={"java":100, "python":112, "c":11} 
  
print(get_key(100)) 
print(get_key(11))
Posted by: Guest on June-12-2020
1

Python - Count the Number of Keys in a Python Dictionary

pythonCopydict1 = {'a':1,'b':2,'c':3}
print(len(dict1.keys()))
Posted by: Guest on May-30-2021
1

get number of key in dictionary python

#Call len(obj) with a dictionary as obj to count the number 
#of key-value pairs in the dictionary.

a_dictionary = {"a": 1, "b": 2}
print(len(a_dictionary))

OUTPUT:
2
Posted by: Guest on October-22-2020

Code answers related to "how to get the number of keys in a dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language