A puzzling Python program
SMRTR summary
This puzzling Python code outputs a countdown from 10 to 1 followed by "True" due to Python's old-style iteration protocol. When "None in countdown(10)" is evaluated, Python iterates through the countdown object by repeatedly calling __getitem__, printing each value until it finds None at index 10 when the countdown reaches zero. The code demonstrates an obscure behavior where Python falls back to sequential indexing when __iter__ isn't defined but __getitem__ is available.
SMRTR provides this summary for quick context. The original article belongs to lobste.rs.
Read the original article