@@ -277,13 +277,13 @@ manageable parts. Thankfully, Python has you covered with `.keys()`,
277277 "Davos": "+244562726258"
278278 }
279279 >>> print(my_phone_book.keys())
280- dict_keys(['Davos ', 'Cersei ', 'Brienne ', 'Arya '])
280+ dict_keys(['Arya ', 'Brienne ', 'Cersei ', 'Davos '])
281281
282282 >>> print(my_phone_book.values())
283- dict_values(['+3206785246863 ', '+14357535455 ', '+244562726258 ', '+4407485376242 '])
283+ dict_values(['+4407485376242 ', '+3206785246863 ', '+14357535455 ', '+244562726258 '])
284284
285285 >>> print(my_phone_book.items())
286- dict_items([('Brienne ', '+3206785246863 '), ('Cersei ', '+14357535455 '), ('Davos ', '+244562726258 '), ('Arya ', '+4407485376242 ')])
286+ dict_items([('Arya ', '+4407485376242 '), ('Brienne ', '+3206785246863 '), ('Cersei ', '+14357535455 '), ('Davos ', '+244562726258 ')])
287287
288288As you can see, ` .keys() ` and ` .values() ` do what you'd expect: they return the
289289keys and values respectively. You may have noticed however that rather than a
@@ -293,19 +293,19 @@ anything with them other than read them as a complete entity, you'll have to
293293cast them as a list:
294294
295295 >>> print(list(my_phone_book.values()))
296- ['+3206785246863 ', '+14357535455 ', '+244562726258 ', '+4407485376242 ']
296+ ['+4407485376242 ', '+3206785246863 ', '+14357535455 ', '+244562726258 ']
297297
298- >>> print(list(my_phone_book.values())[2 ])
298+ >>> print(list(my_phone_book.values())[3 ])
299299 '+244562726258'
300300
301301The last one there, ` .items() ` is interesting. It returns all of the data in
302302your dictionary, but dumps it out as ` dict_items ` which is a sort of * tuple of
303303tuples* . This allows you to reference your dictionary with list syntax:
304304
305- >>> print(tuple(my_phone_book.items())[0 ])
305+ >>> print(tuple(my_phone_book.items())[1 ])
306306 ('Brienne', '+3206785246863')
307307
308- >>> print(tuple(my_phone_book.items())[0 ][1])
308+ >>> print(tuple(my_phone_book.items())[1 ][1])
309309 '+3206785246863'
310310
311311Truth be told though, you probably won't be accessing these values directly
0 commit comments