I work with a function that when you call her it return dictionary, which command shoud I write that will print the keys of the dictionary? Thanks.
Asked
Active
Viewed 86 times
1 Answers
0
You can get an iterable object with the keys by calling your_dict.keys()
>>> my_dict = {'1': 'one', '2': 'two'}
>>> for item in my_dict.keys():
print(item)
1
2

Lelor
- 46
- 4
-
1For the purpose of iterating over the keys, calling `keys()` is not even necessary. – mkrieger1 May 22 '18 at 19:55
-
oh i forgot about that, thank you for pointing it out – Lelor May 23 '18 at 17:52