If x is a string of length 1, return the ascii value. If it's a longer string, return an iterator of values. Otherwise, coerce it to an int() >>> maybe_ord('A') 65 >>> tuple(maybe_ord('lol')) (108, 111, 108) >>> maybe_ord(242) 242 >>> maybe_ord(242.2222) 242
(x)
| 20 | vowels = "aeiouy" |
| 21 | |
| 22 | def maybe_ord(x): |
| 23 | """If x is a string of length 1, return the ascii value. If it's a |
| 24 | longer string, return an iterator of values. Otherwise, coerce it |
| 25 | to an int() |
| 26 | >>> maybe_ord('A') |
| 27 | 65 |
| 28 | >>> tuple(maybe_ord('lol')) |
| 29 | (108, 111, 108) |
| 30 | >>> maybe_ord(242) |
| 31 | 242 |
| 32 | >>> maybe_ord(242.2222) |
| 33 | 242 |
| 34 | """ |
| 35 | try: |
| 36 | if len(x) is 1 and len(x[0]) is 1: |
| 37 | return ord(x) |
| 38 | else: |
| 39 | return itertools.imap(maybe_ord, x) |
| 40 | except: |
| 41 | return int(x) |
| 42 | |
| 43 | |
| 44 | def babble(digest, seed=1): |