Learn Before
Concept
fromkeys(iterable[, value])
fromkeys() is a class method that returns a new dictionary with the specified keys in iterable and the optional value value. If no value is provided the values will default to None. Usage:
students = ('John', 'Joe', 'Jill') grade = 100 student_grades = dict.fromkeys(students, grade) print(student_grades)
The final print statement outputs {'John': 100, 'Joe': 100, 'Jill': 100}.
0
1
Updated 2021-05-17
Tags
Python Programming Language
Data Science