0

How do you get a list of all keys in a dictionary? I know this is a response problem so I really have no place to exactly start the problem.

  • possible duplicate of [How to return dictionary keys as a list in Python 3.3](http://stackoverflow.com/questions/16819222/how-to-return-dictionary-keys-as-a-list-in-python-3-3) – Greg Hewgill Oct 06 '14 at 01:00

1 Answers1

2

Use the .keys() method:

>>> d = {'a': 1, 'b': 2}
>>> print(list(d.keys()))
['a', 'b']
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • The question is tagged Python 3, in which `.keys()` won't return a list. (The OP may not have been using `list` in the type sense, of course.) – DSM Oct 06 '14 at 00:59
  • @DSM: Good catch, thanks. I've updated my answer to match and voted to close as a duplicate. – Greg Hewgill Oct 06 '14 at 01:01