Skip to content

Instantly share code, notes, and snippets.

View tef's full-sized avatar
💭
Please don't try to contact me over GitHub.

tef tef

💭
Please don't try to contact me over GitHub.
View GitHub Profile
@tef
tef / sort.py
Last active December 25, 2015 11:19 — forked from ntlk/sort.py
from sys import stdin, stdout
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-r', action='store_const', const=True, required=False, default=False)
args = parser.parse_args()
stdout.writelines(sorted(stdin.readlines(), reverse = args.r))
@tef
tef / flatten.py
Created January 5, 2013 05:53 — forked from anonymous/flatten.py
import collections
import itertools
def flattened(i):
i = iter(i)
while True:
first = i.next()
if isinstance(first, collections.Iterable):
i = itertools.chain(first, i)
else:
@tef
tef / gist:3688778
Created September 10, 2012 03:52 — forked from dstufft/gist:3688725
import collections
def flatten(input, seen=None):
for item in input:
if isinstance(item, collections.Iterable):
for sub in flatten(item):
yield sub
else:
yield item
@tef
tef / gist:3688768
Created September 10, 2012 03:50 — forked from dstufft/gist:3688762
import collections
def flatten(input):
stack = list(reversed(input))
while stack:
top = stack.pop()
if isinstance(top, collections.Iterable):
stack.extend(list(reversed(top)))
else:
yield top