>>> class Oops(object):
... def __init__(self):
... Oops.__call__ = self
...
>>> x = Oops()
>>> x()
>>> Z = lambda f: (lambda x: f(lambda *args: x(x)(*args)))(lambda x: f(lambda *args: x(x)(*args)))
>>> fact = Z(lambda f: lambda x: 1 if x == 0 else x * f(x-1))
>>> fact(5)
... 120
>>> 0 < 0 == 0
... False
def foo():
return
yield
raise TypeError() from ValueError()
def spam(*, ham):
pass
Move code from try to else if you don't want to catch any errors that it produces.
try:
do_not_do_this_at_home()
except ToldYouSo:
die()
else:
whaddyaknow()
finally:
cleanup()
Yowza!
>>> class attrdict(dict):
... def __init__(self, *args, **kwargs):
... dict.__init__(self, *args, **kwargs)
... self.__dict__ = self
Easy dynamic programming in Python 3.2:
@functools.lru_cache(maxsize=None)
def fib(n):
if n < 2: return n
return fib(n-1) + fib(n-2)
TeX - LaTeX
Q&A for users of TeX, LaTeX, ConTeXt, and related typesetting systems
Meta Stack Overflow
Q&A for meta-discussion of the Stack Exchange family of Q&A websites
Stack Apps
Q&A for apps, scripts, and development with the Stack Exchange API
Mathematics
Q&A for people studying math at any level and professionals in related fields
Theoretical Computer Science
Q&A for theoretical computer scientists and researchers in related fields
Server Fault
Q&A for professional system and network administrators
English Language & Usage
Q&A for linguists, etymologists, and serious English language enthusiasts
Programmers
Q&A for professional programmers interested in conceptual questions about software development
Board & Card Games
Q&A for people who like playing board games, designing board games or modifying the rules of existing board games