Python has predefined fromkeys() method to create a new dictionary from the given sequence of elements.
Syntax of Python fromkeys()
dictionary.fromkeys(sequence[, value])
Here, the sequence is taken as key in creating dictionary and the value parameter is taken as the value in the creating dictionary. The value is an optional parameter. It returns a new dictionary with the given sequence of elements as the keys of the dictionary.
This is the following solution to create a dictionary from the given sequence of keys and value provided by the user -
Solution
Python has predefined fromkeys() method to create a new dictionary from the given sequence of elements.
Syntax of Python fromkeys()
dictionary.fromkeys(sequence[, value])Here, the sequence is taken as key in creating dictionary and the value parameter is taken as the value in the creating dictionary. The value is an optional parameter. It returns a new dictionary with the given sequence of elements as the keys of the dictionary.
This is the following solution to create a dictionary from the given sequence of keys and value provided by the user -
Output of the above code
{'English': 'A', 'Maths': 'A', 'Computer': 'A', 'Science': 'A'}
need an explanation for this answer? contact us directly to get an explanation for this answer