Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
import collections | |
class LinkedList: | |
def __init__(self, value, tail=None): | |
self.value = value | |
self.tail = tail | |
def tee(iterable, n=2): | |
it = iter(iterable) | |
empty = LinkedList(None) |
// We have some state like: | |
const state1 = { | |
data: { some: 'stuff' }, | |
people: ['blah', 'blah', 'blah'], | |
memberships: [ | |
{ id: 1, roles: [], other: 'stuff' }, | |
{ id: 2, roles: ['client'], more: 'junk' } | |
] | |
}; |
// We have some state like: | |
const state1 = { | |
data: { some: 'stuff' }, | |
people: ['blah', 'blah', 'blah'], | |
memberships: [ | |
{ id: 1, roles: [], other: 'stuff' }, | |
{ id: 2, roles: ['client'], more: 'junk' } | |
] | |
}; |
import asyncio | |
import aiofiles # third party package, install from pip | |
# bytes outputted by the imaginary joystick device: | |
CENTER = b'x' | |
NORTH = b'n' | |
EAST = b'e' | |
SOUTH = b's' |
import collections | |
from typing import Counter, List, Set, Tuple | |
def subanagrams(letters: Counter[str], words: Set[str], min_len=4) -> List[Tuple[str, Counter[str]]]: | |
anagrams = [] | |
for word in words: | |
if len(word) < min_len: continue | |
rest = letters.copy() |
Haskell is cool! | |
Here are some reasons why. | |
(This is a Literate Haskell file, so you can load it and then follow | |
along with the examples by running `ghci whyhaskelliscool.lhs`) | |
"Pattern matching" syntax for defining functions is cool, letting you | |
avoid 'if' statements and simply write out the different behaviors of | |
a function: |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!