- Surprising is more ugly than beautiful.
- -- based loosely on PEP 20
Python gotchas and surprising Python facts presented as lightning talk at the PyDays 2019. Inspired by the WAT lightning talk by Gary Bernhardt from CodeMash 2012. This repository contains links to the sources and all material.
Not really part of the lightning talk, but kind of related and also collected and prepared for the PyDays 2019, some mind screwing Python riddles with surprising solutions. Riddles are available for print as PDF and SVG.
Talks about crazy facts in other programing languages than Python:
Mind screwing Python code snippets:
- https://github.com/satwikkansal/wtfpython
- https://www.codementor.io/satwikkansal/some-tricky-python-snippets-that-may-bite-you-off-bhndh45zp
- https://kate.io/blog/2017/08/22/weird-python-integers/
- https://dbader.org/blog/python-mystery-dict-expression
- https://blog.brush.co.nz/2008/01/ten-python-quirkies/
- https://github.com/qezz/python-common-gotchas
- https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make
- https://gist.github.com/brianspiering/6921253524fe0a058d4de8aa0d306c02
- https://www.geeksforgeeks.org/a-b-assignment-riddle-in-python/
- https://www.geeksforgeeks.org/python-a-b-is-not-always-a-a-b/
To type all the Unicode characters, one can cheat a bit by using doitlive. The IPython support is great, but there seems to be a dependency hell. One needs prompt-toolkit==1.x and 5.0<=IPython<7.0.
To install with conda:
$ conda env update -f env-frozen.yml
$ conda activate ugly-surprises
$ PYTHONPATH=$(pwd) doitlive play presentation-part2-unicode.sh
See notes.rst for detailed content of the presentation. 6 workspaces need to be prepared:
- Screen 1: eog white.png
- Screen 2: eog ugly-surprise-with-title.jpg
- Screen 3: ipython or idoitlive presentation-part1.sh
- Screen 4: idoitlive presentation-part2-unicode.sh
- Screen 5: vi mandelbrot.py
- Screen 6: mandelbrot.png
Numpy seems to use [partial pairwise summation in some cases](https://numpy.org/doc/stable/reference/generated/numpy.sum.html), which can lead to different results depending on the data type used:
``` >>> import numpy as np >>> data = [0.042411500823462206, 0.5387831400906496,
2.0907299109640074, 0.012566370614359173, 0.5387831400906496, 0.10053096491487339, 0.5387831400906496, 0.10053096491487339, 0.8042477193189871, 0.1963495408493621, 1.1451105222334796, 1.1451105222334796]
>>> np.sum(np.array(data, dtype=object)) - np.sum(np.array(data, dtype=float))
8.881784197001252e-16
```
Interesting mistakes and surprises without Python: