How to Return Dictionary Keys as a List in Python?
Short answer: use the expression list(dict.keys()). Problem Formulation Given a dictionary that maps keys to values. Return the keys as a list. For example: Given dictionary {‘Alice’: 18, ‘Bob’, 21, ‘Carl’: 24} Return the keys as a list [‘Alice’, ‘Bob’, ‘Carl’] Solution The dict.keys() method returns a list of all keys in Python 2. The … Read more