Swiss Python Summit

This notebook is part of a poster session at #SPS17. Code snippets affixed to the poster were encoded, computed, and the results shared here. Visit our forum for background.

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
X, y = make_blobs(n_samples=2017,centers=99)
plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='rainbow')
Out[1]:
<matplotlib.collections.PathCollection at 0x7f8aa0555b70>

Weirdness

In [2]:
br''or.0jif.1else-2
Out[2]:
0j

Easter eggs

In [3]:
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
In [5]:
import antigravity 
# in Python 3, opens a browser pointing to https://xkcd.com/353/

Python hacks

Not sure what the intent here was?

In [16]:
a=[*'abc']*False
  File "<ipython-input-16-a60b254ebb24>", line 1
    a=[*'abc']*False
      ^
SyntaxError: can use starred expression only as assignment target
In [18]:
int(False)
Out[18]:
0
In [26]:
# I gather at this point we should be seeing something interesting..
False + True
Out[26]:
1

Self referencing

Data below collected using this script.

In [66]:
self_references_in_docs = {
    # https://github.com/bottlepy/bottle
    'Bottle':  {'refs': 6962,   'size': 54583}, 
    # https://docs.djangoproject.com
    'Django':  {'refs': 14941,  'size': 136397}, 
    # http://flask.readthedocs.org
    'Flask':   {'refs': 1306,   'size': 13667}, 
    # https://github.com/Pylons/pyramid
    'Pyramid': {'refs': 5207,   'size': 73288}, 
    # https://github.com/scrapy/scrapy
    'Scrapy':  {'refs': 1760,   'size': 17627}, 
    # https://github.com/tornadoweb/tornado
    'Tornado': {'refs': 928,    'size': 6348}, 
    # https://github.com/twisted/twisted
    'Twisted': {'refs': 5242,   'size': 75888}, 
    # https://github.com/webpy/webpy
    'WebPy':   {'refs': 9,      'size': 1164}, 
}
for t in self_references_in_docs.keys():
    o = self_references_in_docs[t]
    o['avg'] = o['refs']/o['size']
In [65]:
import numpy as np
X = np.arange(len(self_references_in_docs))
Y = [t['avg'] for t in self_references_in_docs.values()]
plt.bar(X, Y, width=0.5)
plt.xticks(X, self_references_in_docs.keys())
plt.show()

Clowning around

In [1]:
fn main() {
    loop {
        println!("Rust is awesome!");
    }
}
  File "<ipython-input-1-b6d5c13fafdd>", line 1
    fn main() {
          ^
SyntaxError: invalid syntax

This raises the question of how to add Rust code to Jupyter notebooks, something this project attempts to answer: https://github.com/pwoolcoc/jupyter-rs

For a survey of supported languages see: https://github.com/jupyter/jupyter/wiki/Jupyter-kernels