Skip to content

lumbric/ugly-surprises

Repository files navigation

Ugly Surprises MIT License

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.

Riddles

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:

How to run code snippets

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

Presentation

See notes.rst for detailed content of the presentation. 6 workspaces need to be prepared:

Surpising code snippets not (yet) used here

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`

Unrelated mistakes

Interesting mistakes and surprises without Python:

About

Python gotchas and other surprising facts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published