@@ -196,7 +196,7 @@ a dictionary for a phone book:
196
196
197
197
my_phone_book = {
198
198
"Arya": "+4407485376242",
199
- "Breanne ": "+3206785246863",
199
+ "Brienne ": "+3206785246863",
200
200
"Cersei": "+14357535455",
201
201
"Davos": "+244562726258"
202
202
}
@@ -217,7 +217,7 @@ You can have *anything* in there:
217
217
"a list": ["This", "is my", "list"],
218
218
"another dictionary!": {
219
219
"Arya": "+4407485376242",
220
- "Breanne ": "+3206785246863",
220
+ "Brienne ": "+3206785246863",
221
221
"Cersei": "+14357535455",
222
222
"Davos": "+244562726258"
223
223
}
@@ -247,7 +247,7 @@ doing this should hopefully feel intuitive by now:
247
247
248
248
Change a value for a key:
249
249
250
- my_phone_book["Breanne "] = "+830685432195"
250
+ my_phone_book["Brienne "] = "+830685432195"
251
251
252
252
Add a new key/value pair:
253
253
@@ -270,18 +270,18 @@ manageable parts. Thankfully, Python has you covered with `.keys()`,
270
270
271
271
>>> my_phone_book = {
272
272
"Arya": "+4407485376242",
273
- "Breanne ": "+3206785246863",
273
+ "Brienne ": "+3206785246863",
274
274
"Cersei": "+14357535455",
275
275
"Davos": "+244562726258"
276
276
}
277
277
>>> my_phone_book.keys()
278
- dict_keys(['Davos', 'Cersei', 'Breanne ', 'Arya'])
278
+ dict_keys(['Davos', 'Cersei', 'Brienne ', 'Arya'])
279
279
280
280
>>> my_phone_book.values()
281
281
dict_values(['+3206785246863', '+14357535455', '+244562726258', '+4407485376242'])
282
282
283
283
>>> my_phone_book.items()
284
- dict_items([('Breanne ', '+3206785246863'), ('Cersei', '+14357535455'), ('Davos', '+244562726258'), ('Arya', '+4407485376242')])
284
+ dict_items([('Brienne ', '+3206785246863'), ('Cersei', '+14357535455'), ('Davos', '+244562726258'), ('Arya', '+4407485376242')])
285
285
286
286
As you can see, ` .keys() ` and ` .values() ` do what you'd expect: they return the
287
287
keys and values respectively. You may have noticed however that rather than a
@@ -301,7 +301,7 @@ your dictionary, but dumps it out as `dict_items` which is a sort of *tuple of
301
301
tuples* . This allows you to reference your dictionary with list syntax:
302
302
303
303
>>> tuple(my_phone_book.items())[0]
304
- ('Breanne ', '+3206785246863')
304
+ ('Brienne ', '+3206785246863')
305
305
306
306
>>> tuple(my_phone_book.items())[0][1]
307
307
'+3206785246863'
0 commit comments