- fromkeys() is a python function which are used to insert a new keys in the dictionary.
Syntax-
dict.fromkeys(key)
Example
dictionary is d={1:"one",2:"two"}
then d.fromkeys(3) will give {1:"one",2:"two",3:None}
program-
print("We store data of three keys")
d=dict()
print("Enter first key")
k=input()
d.fromkeys(k)
print("Enter value for first key")
d[k]=input()
print("Enter second key")
k=input()
d.fromkeys(k)
print("Enter value for second key")
d[k]=input()
print("Enter third key")
k=input()
d.fromkeys(k)
print("Enter value for third key")
d[k]=input()
print("Dictionary is ")
print(d)
We store data of three keys
Enter first key
1
Enter value for first key
one
Enter second key
2
Enter value for second key
two
Enter third key
3
Enter value for third key
three
{'1': 'one', '2': 'two', '3': 'three'}