Python Dictionary fromkeys() Method Syntax

Syntax : fromkeys(seq, val)

Parameters :

  • seq : The sequence to be transformed into a dictionary.
  • val : Initial values that need to be assigned to the generated keys. Defaults to None.

Returns : A dictionary with keys mapped to None if no value is provided, else to the value provided in the field. 

Python Dictionary fromkeys() Method

Python dictionary fromkeys() function returns the dictionary with key mapped and specific value. It creates a new dictionary from the given sequence with the specific value.

Similar Reads

Python Dictionary fromkeys() Method Syntax:

Syntax : fromkeys(seq, val) Parameters : seq : The sequence to be transformed into a dictionary. val : Initial values that need to be assigned to the generated keys. Defaults to None. Returns : A dictionary with keys mapped to None if no value is provided, else to the value provided in the field....

Python Dictionary fromkeys() Method Example:

Python3 seq = ('a', 'b', 'c') print(dict.fromkeys(seq, None))...