File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 92
92
" pathobj" ,
93
93
" pipenv" ,
94
94
" Pipfile" ,
95
+ " popitem" ,
95
96
" pprint" ,
96
97
" prereleases" ,
97
98
" prismjs" ,
Original file line number Diff line number Diff line change @@ -148,6 +148,54 @@ Using `setdefault` we could make the same code more short:
148
148
# {'name': 'Rose', 'age': 33, 'has_hair': True}
149
149
```
150
150
151
+ ## Removing Items
152
+
153
+ ### pop()
154
+
155
+ ` pop() ` removes an item based on a given key.
156
+
157
+ ``` python
158
+ >> > wife = {' name' : ' Rose' , ' age' : 33 , ' hair' : ' brown' }
159
+ >> > wife.pop(' age' )
160
+ # 33
161
+ >> > wife
162
+ # {'name': 'Rose', 'hair': 'brown'}
163
+ ```
164
+
165
+ ### popitem()
166
+
167
+ ` popitem() ` remove the last item in a dictionary and returns it.
168
+
169
+ ``` python
170
+ >> > wife = {' name' : ' Rose' , ' age' : 33 , ' hair' : ' brown' }
171
+ >> > wife.popitem()
172
+ # ('hair', 'brown')
173
+ >> > wife
174
+ # {'name': 'Rose', 'age': 33}
175
+ ```
176
+
177
+ ### del()
178
+
179
+ ` del() ` removes an item based on a given key.
180
+
181
+ ``` python
182
+ >> > wife = {' name' : ' Rose' , ' age' : 33 , ' hair' : ' brown' }
183
+ >> > del wife[' age' ]
184
+ >> > wife
185
+ # {'name': 'Rose', 'hair': 'brown'}
186
+ ```
187
+
188
+ ### clear()
189
+
190
+ ` clear() ` removes all the items in a dictionary.
191
+
192
+ ``` python
193
+ >> > wife = {' name' : ' Rose' , ' age' : 33 , ' hair' : ' brown' }
194
+ >> > wife.clear()
195
+ >> > wife
196
+ # {}
197
+ ```
198
+
151
199
## Pretty Printing
152
200
153
201
``` python
You can’t perform that action at this time.
0 commit comments