File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,12 +67,12 @@ recently:
6767.. code :: python
6868
6969 mcase = {' a' : 10 , ' b' : 34 , ' A' : 7 , ' Z' : 3 }
70-
70+
7171 mcase_frequency = {
7272 k.lower(): mcase.get(k.lower(), 0 ) + mcase.get(k.upper(), 0 )
7373 for k in mcase.keys()
7474 }
75-
75+
7676 # mcase_frequency == {'a': 17, 'z': 3, 'b': 34}
7777
7878 In the above example we are combining the values of keys which are same
@@ -87,14 +87,10 @@ comprehensions a lot. You can also quickly switch keys and values of a dictionar
8787^^^^^^^^^^^^^^^^^^^^^^
8888
8989They are also similar to list comprehensions. The only difference is
90- that they use round brackets ``() `` and return a generator. Here is an
91- example:
90+ that they use braces ``{} ``. Here is an example:
9291
9392.. code :: python
9493
95- squared = (x ** 2 for x in range ( 10 ))
94+ squared = {x for x in [ 1 , 1 , 2 ]}
9695 print (squared)
97- # Output: <generator object <genexpr> at 0x00000000029931B0>
98- squared.next()
99- # Output: 0
100-
96+ # Output: {1, 2}
You can’t perform that action at this time.
0 commit comments