Skip to content

Instantly share code, notes, and snippets.

@ojii
Created March 30, 2011 09:10
Show Gist options
  • Save ojii/894103 to your computer and use it in GitHub Desktop.
Save ojii/894103 to your computer and use it in GitHub Desktop.
A python script that translates German to Swiss German
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import random
mappings = {
'a': u'ä',
'o': u'ö',
'u': u'ü',
'k': 'ch',
}
def _swissify_single(bit, i):
if bit not in mappings:
return bit
choices = [bit] + [mappings[bit] for x in range(i)]
return random.choice(choices)
def swissify(value, i):
return ''.join([_swissify_single(bit, i) for bit in value])
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-i', default=1, type=int)
parser.add_argument('data')
namespace = parser.parse_args()
print swissify(namespace.data, namespace.i)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment