This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author TobiasHT
Recipients TobiasHT
Date 2021-12-28.10:00:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1640685602.96.0.10576142491.issue46188@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-12-28 10:00:03TobiasHTsetrecipients: + TobiasHT
2021-12-28 10:00:02TobiasHTsetmessageid: <1640685602.96.0.10576142491.issue46188@roundup.psfhosted.org>
2021-12-28 10:00:02TobiasHTlinkissue46188 messages
2021-12-28 10:00:02TobiasHTcreate