Skip to main content
Katriel's user avatar
Katriel's user avatar
Katriel's user avatar
Katriel
Student, Pythonista
  • Member for 15 years, 8 months
  • Last seen more than 4 years ago

Stats

124,296
reputation
22.8m
reached
823
answers
8
questions
Loading…

About

SOreadytohelp, apparently :)

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 

@functools.lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-1) + fib(n-2) 
19
gold badges
141
silver badges
173
bronze badges
11,803
Score
813
Posts
98
Posts %
1,072
Score
50
Posts
6
Posts %
381
Score
26
Posts
3
Posts %
232
Score
26
Posts
3
Posts %
180
Score
28
Posts
3
Posts %
165
Score
19
Posts
2
Posts %

Top posts

View all questions, answers, and articles