Skip to content

Commit c595143

Browse files
committed
chore: update titles
1 parent 971aef6 commit c595143

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

Diff for: docs/cheatsheet/dictionaries.md

+41-41
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ myCat = {
2626
}
2727
```
2828

29-
## The values() method
29+
## values()
3030

31-
Get the **values** of the dictionary:
31+
The `values()` method gets the **values** of the dictionary:
3232

3333
```python
3434
>>> pet = {'color': 'red', 'age': 42}
@@ -39,9 +39,9 @@ Get the **values** of the dictionary:
3939
# 42
4040
```
4141

42-
## The keys() method
42+
## keys()
4343

44-
Get the **keys** of the dictionary:
44+
The `keys()` method gets the **keys** of the dictionary:
4545

4646
```python
4747
>>> pet = {'color': 'red', 'age': 42}
@@ -52,9 +52,9 @@ Get the **keys** of the dictionary:
5252
# age
5353
```
5454

55-
## The items() method
55+
## items()
5656

57-
Get the **items** of a dictionary and return them as a [Tuple](/cheatsheet/lists-and-tuples#the-tuple-data-type):
57+
The `items()` method gets the **items** of a dictionary and return them as a <router-link to=/cheatsheet/lists-and-tuples#the-tuple-data-type>Tuple</router-link>:
5858

5959
```python
6060
>>> pet = {'color': 'red', 'age': 42}
@@ -76,36 +76,9 @@ Using the `keys()`, `values()`, and `items()` methods, a for loop can iterate ov
7676
# Key: age Value: 42
7777
```
7878

79-
## Checking keys in a Dictionary
80-
81-
```python
82-
>>> person = {'name': 'Rose', 'age': 33}
83-
84-
>>> 'name' in person.keys()
85-
# True
86-
87-
>>> 'height' in person.keys()
88-
# False
89-
90-
>>> 'skin' in person # You can omit keys()
91-
# False
92-
```
93-
94-
## Checking values in a Dictionary
95-
96-
```python
97-
>>> person = {'name': 'Rose', 'age': 33}
98-
99-
>>> 'Rose' in person.values()
100-
# True
101-
102-
>>> 33 in person.values()
103-
# False
104-
```
105-
106-
## The get() Method
79+
## get()
10780

108-
The `get` method returns the value of an item with by using the key. If the key doesn't exist, it returns `None`:
81+
The `get()` method returns the value of an item with by using the key. If the key doesn't exist, it returns `None`:
10982

11083
```python
11184
>>> wife = {'name': 'Rose', 'age': 33}
@@ -129,7 +102,7 @@ You can also change the default `None` value for other of your choice:
129102
# 'She is deeply in love with lover'
130103
```
131104

132-
## The setdefault() Method
105+
## Adding items with setdefault()
133106

134107
It's possible to add an item to a dictionary in this way:
135108

@@ -139,7 +112,7 @@ It's possible to add an item to a dictionary in this way:
139112
... wife['has_hair'] = True
140113
```
141114

142-
Using `setdefault` we could make the same code more short:
115+
Using the `setdefault` method we can make the same code more short:
143116

144117
```python
145118
>>> wife = {'name': 'Rose', 'age': 33}
@@ -152,7 +125,7 @@ Using `setdefault` we could make the same code more short:
152125

153126
### pop()
154127

155-
`pop()` removes an item based on a given key.
128+
The `pop()` method removes an item based on a given key.
156129

157130
```python
158131
>>> wife = {'name': 'Rose', 'age': 33, 'hair': 'brown'}
@@ -164,7 +137,7 @@ Using `setdefault` we could make the same code more short:
164137

165138
### popitem()
166139

167-
`popitem()` remove the last item in a dictionary and returns it.
140+
The `popitem()` method remove the last item in a dictionary and returns it.
168141

169142
```python
170143
>>> wife = {'name': 'Rose', 'age': 33, 'hair': 'brown'}
@@ -176,7 +149,7 @@ Using `setdefault` we could make the same code more short:
176149

177150
### del()
178151

179-
`del()` removes an item based on a given key.
152+
The `del()` method removes an item based on a given key.
180153

181154
```python
182155
>>> wife = {'name': 'Rose', 'age': 33, 'hair': 'brown'}
@@ -187,7 +160,7 @@ Using `setdefault` we could make the same code more short:
187160

188161
### clear()
189162

190-
`clear()` removes all the items in a dictionary.
163+
The`clear()` method removes all the items in a dictionary.
191164

192165
```python
193166
>>> wife = {'name': 'Rose', 'age': 33, 'hair': 'brown'}
@@ -196,6 +169,33 @@ Using `setdefault` we could make the same code more short:
196169
# {}
197170
```
198171

172+
## Checking keys in a Dictionary
173+
174+
```python
175+
>>> person = {'name': 'Rose', 'age': 33}
176+
177+
>>> 'name' in person.keys()
178+
# True
179+
180+
>>> 'height' in person.keys()
181+
# False
182+
183+
>>> 'skin' in person # You can omit keys()
184+
# False
185+
```
186+
187+
## Checking values in a Dictionary
188+
189+
```python
190+
>>> person = {'name': 'Rose', 'age': 33}
191+
192+
>>> 'Rose' in person.values()
193+
# True
194+
195+
>>> 33 in person.values()
196+
# False
197+
```
198+
199199
## Pretty Printing
200200

201201
```python

0 commit comments

Comments
 (0)