Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 10, 2020
Embed
What would you like to do?
#fromkeys()
#fromkeys() method returns a dictionary with the specified keys and the specified value.
a={'a','e','i','o','u'}
b='vowels'
d1=dict.fromkeys(a,b)
print(d1)
#Output: {'o': 'vowels', 'u': 'vowels', 'e': 'vowels', 'i': 'vowels', 'a': 'vowels'}
#dictionary is unordered.
#if value is not mentioned,it defaults to None.
d2=dict.fromkeys(a)
print (d2)#Output:{'e': None, 'a': None, 'u': None, 'i': None, 'o': None}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment