Mercurial > hg > config
annotate python/accentuate.py @ 177:6ae566bb1a99
add an example of lack of python closures
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 03 Nov 2011 10:39:22 -0700 |
parents | 01fb9051faf8 |
children | 952ba8de70d8 |
rev | line source |
---|---|
125
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 import random |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
162 | 6 mapping = {'a': ['Ȁ', 'ȁ', 'à', 'Ѧ', 'ª', 'Å', 'Ą'], |
7 'b': ['Б', 'ß'], | |
125
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 'c': ['ç'], |
162 | 9 'd': ['Ð', 'đ'], |
10 'e': ['ȅ', 'Ё', 'Є', 'Ę'], | |
161 | 11 'l': ['£', '₤'], |
136 | 12 'n': ['И', 'Й'], |
13 'o': ['ổ', 'ȍ', 'Ѳ'], | |
162 | 14 's': ['∫', '§'], |
125
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 't': ['Ṱ'], |
136 | 16 'v': ['Ѵ'], |
17 'w': ['Ѡ', 'Щ'] | |
125
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 } |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 if __name__ == '__main__': |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 import sys |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 arg = ' '.join(sys.argv[1:]) |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 retval = [] |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 for letter in arg: |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 if letter.lower() in mapping: |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
26 retval.append(random.sample(mapping[letter.lower()], 1)[0]) |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
27 else: |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 retval.append(letter) |
a51df2382390
new program that does silly things
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 print ''.join(retval) |