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 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)) |
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 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: |
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 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 |
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 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 |