Python Dictionary fromkeys() method

The dictionary.fromkeys() method in Python creates a new dictionary from the given sequence of elements and returns a dictionary with the specified keys and values.

Syntax

Parameter

sequence- This parameter represents the sequence of elements which is to be used as keys for the new dictionary.

value(optional)- This argument signifies the value which is set for each element of the dictionary.

Return

This method returns a dictionary with the specified keys and values.

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This