File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ The code below demonstrates the old syntax of dict initialization. Although ther
10
10
11
11
.. code :: python
12
12
13
- l = [1 ,2 ,3 ]
13
+ numbers = [1 ,2 ,3 ]
14
14
15
- d = dict ([(n,n * 2 ) for n in l ]) # hard to read
15
+ my_dict = dict ([(number,number * 2 ) for number in numbers ]) # hard to read
16
16
17
- print d # {1: 2, 2: 4, 3: 6}
17
+ print my_dict # {1: 2, 2: 4, 3: 6}
18
18
19
19
Best practice
20
20
-------------
@@ -23,11 +23,11 @@ The modified code below uses the new dict comprehension syntax which was introdu
23
23
24
24
.. code :: python
25
25
26
- l = [1 , 2 , 3 ]
26
+ numbers = [1 , 2 , 3 ]
27
27
28
- d = {n: n * 2 for n in l }
28
+ my_dict = {number: number * 2 for number in numbers }
29
29
30
- print d # {1: 2, 2: 4, 3: 6}
30
+ print my_dict # {1: 2, 2: 4, 3: 6}
31
31
32
32
References
33
33
----------
You can’t perform that action at this time.
0 commit comments