Light Mode
Dark Mode
Coding Tip: dict.fromkeys

There is a function dict.fromkeys I haven’t paid much attention to, but it can be very useful in many cases.

>>> all_students = ('Alex', 'Mike', 'Nick', 'John')
>>> dict.fromkeys(all_students, 0)
{'Alex': 0, 'Mike': 0, 'Nick': 0, 'John': 0}
  • python
  • tips
Created: Dec. 28, 2017, 3:59 p.m.
Updated: Dec. 31, 2017, 6:52 a.m.
1
40
User avatar
oduvan