Skip to content

Instantly share code, notes, and snippets.

@skwerlman
Last active January 4, 2017 05:46
Show Gist options
  • Save skwerlman/d3784a65e1e99e515019b6891a1044fa to your computer and use it in GitHub Desktop.
Save skwerlman/d3784a65e1e99e515019b6891a1044fa to your computer and use it in GitHub Desktop.
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