Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/ccefe6feb0936b700d389bc48410a5ea to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/ccefe6feb0936b700d389bc48410a5ea to your computer and use it in GitHub Desktop.
#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