+-------------------+-------+------+ | Character | Lives | Dies | +===================+=======+======+ | Walter White | X | | +-------------------+-------+------+ | Skyler White | X | | +-------------------+-------+------+ | Jesse Pinkman | | X | + +-------+------+ | | Uncle Jack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kombu import Connection, Exchange, Queue | |
from kombu.mixins import ConsumerMixin | |
queue = Queue('hello', exchange=Exchange('hello', type='direct'), | |
routing_key='hello') | |
class Worker(ConsumerMixin): | |
def __init__(self, connection): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def balanced(s): | |
unmatched = 0 | |
for c in s: | |
if c == ')': | |
if not unmatched: | |
return False | |
unmatched -= 1 | |
elif c == '(': | |
unmatched += 1 | |
return unmatched == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[MASTER] | |
# Specify a configuration file. | |
#rcfile= | |
# Python code to execute, usually for sys.path manipulation such as | |
# pygtk.require(). | |
#init-hook= | |
# Profiled execution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_pandigital(*args, n=9): | |
values = set(''.join(map(str, args))) | |
return '0' not in values and len(values) == n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain, islice | |
s1 = '4K Media' | |
s2 = '53 W. 23rd St.' | |
s3 = ''.join(chain(islice(filter(str.isalnum, s1), 4), | |
islice(filter(str.isalnum, s2), 8))) | |
assert s3 == '4KMe53W23rdS' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import floor, log | |
def digits(n): | |
yield from (n // (10 ** x) % 10 for x in range(floor(log(n, 10)), -1, -1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
import curses | |
from random import randrange, shuffle | |
from time import sleep | |
def display(stdscr, state): | |
stdscr.addstr(0, 0, ' '.join(state)) | |
stdscr.addstr(1, 0, ' ' * (len(state) // 2) + '\u2191') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from weakref import WeakKeyDictionary | |
class Skippable(object): | |
def __init__(self, field_name): | |
self.data = WeakKeyDictionary() | |
self.field_name = field_name | |
def __get__(self, instance, owner): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
PY2 = sys.version_info[0] == 2 | |
if PY2: | |
_iteritems = 'iteritems' | |
_iterkeys = 'iterkeys' | |
_itervalues = 'itervalues' | |
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb') |