Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#!/usr/bin/env python | |
import os | |
import random | |
import time | |
import platform | |
snowflakes = {} | |
try: | |
# Windows Support |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
# nanoshorten - a very tiny URL shortener Web application written in Bottle and sqlite | |
# copyright (c) 2012 darkf | |
# licensed under the WTFPL (WTF Public License) | |
# see http://sam.zoy.org/wtfpl/ for details | |
from bottle import get, request, run | |
import sqlite3, random, string | |
con = sqlite3.connect('short.db') | |
c = con.cursor() |
#!/usr/bin/python | |
from collections import defaultdict | |
def slow(num_immortals): | |
stack = [1 << x for x in range(num_immortals)] | |
seen = [] | |
while stack: | |
gene = stack.pop() |
##Google Interview Questions: Product Marketing Manager
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
typedef unsigned int u32; | |
typedef unsigned long long u64; | |
//------------------------------------------------------------------------- | |
// WorkArea | |
//------------------------------------------------------------------------- |
""" | |
MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm | |
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All | |
rights reserved. | |
License to copy and use this software is granted provided that it | |
is identified as the "RSA Data Security, Inc. MD5 Message-Digest | |
Algorithm" in all material mentioning or referencing this software | |
or this function. |
def log_gen(n): | |
import math | |
y = 1 | |
while y < n: | |
adder = max(1, math.pow(10, int(math.log10(y)))) | |
yield int(y) | |
y = y + adder |
#! /usr/bin/env python | |
"""{escher} -- one-file key-value storage. | |
What? | |
This is a toy application to manage persistent key-value string data. | |
The file {escher} is *both* the application and its data. | |
When you run any of the commands below, the file will be executed and, | |
after data change, it will rewrite itself with updated data. | |
You can copy the file with whatever name to create multiple datasets. |
# -*- coding: utf-8 -*- | |
# seq 5000 | xargs -P100 -I% python2 selfdb.py k% v% | |
'''{prog} -- self-logging in-memory key-value storage | |
Usage: | |
Display Keys | |
{prog} | |
Get Value of Key | |
{prog} some-key |