Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # if this is somehow copyrightable then cc0 (do whatever): https://creativecommons.org/publicdomain/zero/1.0/
- import math
- import string
- alphabet = string.ascii_lowercase + "&"
- upside_down = {}
- for i in range(len(alphabet)):
- upside_down[alphabet[i]] = alphabet[math.floor(i/9)*9 + 8-(i%9)] # 012345678 -> 876543210
- def flip(s):
- return "".join([upside_down[i] if i in upside_down else i for i in s])[::-1]
- with open("words.txt", "r") as f:
- words = {word.lower() : 0 for word in f.read().splitlines()} # dict is hashmap so fast lookup
- found = {} # dict keeps order so we can preserve the alphabetizedness
- for i in words:
- if flip(i) in words:
- found[tuple(sorted((i, flip(i))))] = None
- found = sorted(found, key = lambda i: len(i[0]), reverse = True)
- print(len(found))
- with open("elian ambigrams.txt", "w") as f:
- f.write("\n".join([" ".join(i) for i in found]))
Add Comment
Please, Sign In to add comment