Message409251
I was creating a dictionary when I noticed something weird.
I had a function responsible for creating dictionary keys and then values were assigned to the keys in a for loop.
The code goes a little like this:
>>> def key_maker(n):
... if (n % 2) == 0:
... return n
... return None
>>> dictionary = {}
>>> for i in range(10):
... dictionary[key_maker(i)] = i if key_maker(i) else "error"
>>> dictionary
{0: 'error', None: 'error', 2: 2, 4: 4, 6: 6, 8: 8}
when I tried to print out the rest of the values in the "else" clause,
I realized that 0 appeared there as well, so 0 appeared twice.
>>> for i in range(10):
... dictionary[key_maker(i)] = i if key_maker(i) else print(i)
...
0
1
3
5
7
9
>>> dictionary
{0: 'error', None: 'error', 2: 2, 4: 4, 6: 6, 8: 8}
I still can not figure out why the first two elements are inconsistent
from the rest of the dictionary, and why they appear in the first place. |
|
Date |
User |
Action |
Args |
2021-12-28 10:00:03 | TobiasHT | set | recipients:
+ TobiasHT |
2021-12-28 10:00:02 | TobiasHT | set | messageid: <1640685602.96.0.10576142491.issue46188@roundup.psfhosted.org> |
2021-12-28 10:00:02 | TobiasHT | link | issue46188 messages |
2021-12-28 10:00:02 | TobiasHT | create | |
|