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!
Also, he is the author of the famous TimSort algorithm: https://en.wikipedia.org/wiki/Timsort def tee(iterable, n=2):
iterator = iter(iterable)
shared_link = [None, None]
return tuple(_tee(iterator, shared_link) for _ in range(n))
def _tee(iterator, link):
try:
while True:
if link[1] is None:
link[0] = next(iterator)
link[1] = [None, None]
value, link = link
yield value
except StopIteration:
return from random import Random
from math import ldexp
class FullRandom(Random):
def random(self):
mantissa = 0x10_0000_0000_0000 | self.getrandbits(52)
exponent = -53
x = 0
while not x:
x = self.getrandbits(32)
exponent += x.bit_length() - 32
return ldexp(mantissa, exponent)
[0] https://docs.python.org/3/library/random.html#recipes Variable and attribute read access:
1.9 ns read_local
2.4 ns read_nonlocal
2.8 ns read_global
4.1 ns read_builtin
5.0 ns read_classvar_from_class
12.1 ns read_classvar_from_instance
4.8 ns read_instancevar
4.7 ns read_instancevar_slots
12.2 ns read_namedtuple
29.0 ns read_boundmethod
Variable and attribute write access:
2.4 ns write_local
2.5 ns write_nonlocal
10.5 ns write_global
26.8 ns write_classvar
4.3 ns write_instancevar
4.2 ns write_instancevar_slots
Data structure read access:
5.7 ns read_list
11.1 ns read_deque
10.1 ns read_dict
10.5 ns read_strdict
Data structure write access:
6.2 ns write_list
11.3 ns write_deque
11.2 ns write_dict
12.0 ns write_strdict
Stack (or queue) operations:
18.4 ns list_append_pop
17.8 ns deque_append_pop
18.1 ns deque_append_popleft
Cleve's papers were an inspiration. I soon published my own matrix package called matfunc. That work was heavily influenced by Cleve Moler and by algorithms in Golub and Van Loan. Even my more recent Python contributions, like the super accurate math.fsum(), math.hypot(), and math.sumprod() functions, have their roots in that fertile time in the Matlab ecosystem. In particular, it newsgroups and lists of papers taught me Cleve's never ending quest to create clean front-ends for numerically sophisticated code.
Thank you Cleve. Your legacy will live forever.