RE: https://mastodon.social/@bmispelon/116239619637209841

That's a #PythonOddity!

See spoiler reply for the explanation.

#Python

SnoopJ (@[email protected])

This is your periodic reminder that `0xfor....real` is a syntactically-valid AND error-free #Python program

Hachyderm.io
Here's a #PythonOddity for you. You can use `float('nan')` as a key in a dictionary. But if you then try to access `my_dict[float('nan')]` you'll get a `KeyError`. If you assign `float('nan')` to a variable and then use that variable to set/access the dictionary that will work.
This happens because `float('nan') != float('nan')`. Even though the hashes are the same, the values are unequal and the dictionary lookup includes an equality check.

RE: https://mastodon.social/@danzin/116076832515812187

An interesting #PythonOddity that I'm surprised I haven't encountered before.

RE: https://mastodon.social/@bmispelon/116041593220352595

Test your mental model of Python's import system. ๐Ÿคจ

#PythonOddity #Python

@treyhunner Tagging you on this since it might qualify as a #Pythonoddity

RE: https://mastodon.social/@carapace/115339525169475036

This one's fun!

An infinite iterable from a finite data structure? ๐Ÿค”

It all works because lists can "contain" themselves.

Remember that lists don't actually contain data in Python but references to data.

#PythonOddity

In honor of today's date of September 12th, I came up with a #PythonOddity puzzle.

Can you guess the redacted module from the standard library (no pip install allowed!) such that:

from โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ import โ–ˆโ–ˆโ–ˆโ–ˆ, โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ
A = โ–ˆโ–ˆโ–ˆโ–ˆ(12, 12, 12)
B = โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ(12, 12, 12, 12, 12, 12)
assert (A + B + B) != (B + B + A) # huh
assert (A + B + B) != (A + 2 * B) # this also works

#PythonOddity /cc @bmispelon

Plus an alternative to x += 1:

x -=~ 0

Am I the only one who didn't know that #Python list comprehensions (and presumably other types of comprehensions) can accept **multiple** conditional statements at the end?

[i for i in range(30) if i%2 if i%3 if i%5]

#PythonOddity