Python Tutorial, Release 3.9.5 Chapter 5. Data Structures 38 >>> tel={ 'jack':4098 ,'sape':4139 } >>> tel['guido'] =4127 >>> tel {'jack': 4098, 'sape': 4139, 'guido': 4127} >>> tel['jack'] 4098 >>>del tel['sape'] >>> tel['irv'] =4127 >>> tel {'jack': 4098, 'guido': 4127, 'irv': 4127} >>> list(tel) ['jack', 'guido', 'irv'] >>> sorted(tel) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False The$_{dict()}$ constructor builds dictionaries directly from sequences of key-value pairs: In addition, dict comprehensions can be used to create dictionaries from arbitrary key and value expressions: When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments: When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the items() method. When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the$_{enumerate()}$ function. To loop over two or more sequences at the same time, the entries can be paired with the$_{zip()}$function. >>>for i, v in enumerate(['tic','tac','toe']): ... print(i, v) ... 0 tic 1 tac 2 toe >>> knights ={ 'gallahad':'the pure','robin':'the brave'} >>>for k, v in knights.items(): ... print(k, v) ... gallahad the pure robin the brave >>> dict(sape=4139 , guido=4127 , jack=4098 ) {'sape': 4139, 'guido': 4127, 'jack': 4098} >>> dict([( 'sape',4139 ), ( 'guido',4127 ), ( 'jack',4098 )]) {'sape': 4139, 'guido': 4127, 'jack': 4098} >>> {x: x**2 for x in (2,4,6)} {2: 4, 4: 16, 6: 36} 5.6 Looping Techniques