Skip to content

Commit f9bc715

Browse files
authored
Added default loop through dictionary keys
1 parent 28f6dbc commit f9bc715

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: docs/cheatsheet/dictionaries.md

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ The `keys()` method gets the **keys** of the dictionary:
5555
# color
5656
# age
5757
```
58+
there is no need to use **.keys()** since by default you will loop through keys:
59+
```python
60+
>>> pet = {'color': 'red', 'age': 42}
61+
>>> for key in pet:
62+
... print(key)
63+
...
64+
# color
65+
# age
66+
```
67+
5868

5969
## items()
6070

0 commit comments

Comments
 (0)