@@ -31,6 +31,7 @@ def test_dictionary():
3131 }
3232
3333 assert isinstance (fruits_dictionary , dict )
34+ assert not isinstance (fruits_dictionary , list )
3435
3536 # You may access set elements by keys.
3637 assert fruits_dictionary ['apple' ] == 'green'
@@ -59,6 +60,7 @@ def test_dictionary():
5960
6061 # The dict() constructor builds dictionaries directly from sequences of key-value pairs.
6162 dictionary_via_constructor = dict ([('sape' , 4139 ), ('guido' , 4127 ), ('jack' , 4098 )])
63+ assert {'a' : 1 , 'b' : 2 , 'c' : 3 } == dict ([('a' , 1 ), ('b' , 2 ), ('c' , 3 )])
6264
6365 assert dictionary_via_constructor ['sape' ] == 4139
6466 assert dictionary_via_constructor ['guido' ] == 4127
@@ -67,13 +69,17 @@ def test_dictionary():
6769 # In addition, dict comprehensions can be used to create dictionaries from arbitrary key
6870 # and value expressions:
6971 dictionary_via_expression = {x : x ** 2 for x in (2 , 4 , 6 )}
72+ xx = {x : (x + y ) for x in range (2 ) for y in range (2 )}
73+ print (xx )
7074 assert dictionary_via_expression [2 ] == 4
7175 assert dictionary_via_expression [4 ] == 16
7276 assert dictionary_via_expression [6 ] == 36
7377
7478 # When the keys are simple strings, it is sometimes easier to specify pairs using
7579 # keyword arguments.
7680 dictionary_for_string_keys = dict (sape = 4139 , guido = 4127 , jack = 4098 )
81+
82+ assert dict (xy = 1 , yz = 2 , xz = 3 ) == {'xy' : 1 , 'yz' : 2 , "xz" : 3 }
7783 assert dictionary_for_string_keys ['sape' ] == 4139
7884 assert dictionary_for_string_keys ['guido' ] == 4127
7985 assert dictionary_for_string_keys ['jack' ] == 4098
0 commit comments