Last active
January 4, 2017 05:46
-
-
Save skwerlman/d3784a65e1e99e515019b6891a1044fa to your computer and use it in GitHub Desktop.
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 | |
def usage(): | |
sys.stdout.write('usage: replace.py pairing [pairing ...]') | |
sys.stdout.write(' a pairing is a char and what to replace it with') | |
sys.stdout.write(' e.g. replace.py a A would replace all \'a\' with \'A\'') | |
sys.exit(1) | |
def group2(l): | |
return zip(*[iter(l)]*2) | |
if len(sys.argv) < 2: | |
usage() | |
args = sys.argv[1:] | |
if len(args) % 2 != 0: | |
usage() | |
reps = {} | |
for argA, argB in group2(args): | |
reps[argA] = argB | |
for line in sys.stdin.readlines(): | |
chunkbylen = {} | |
for pair in reps: | |
line = line.replace(pair, reps[pair]) | |
sys.stdout.write(line) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment