11 "import unicodedata\n",
23 "unaccent_specials = ''.maketrans({\"’\": \"'\", '“': '\"', '”': '\"'})"
34 "def unaccent(text):\n",
35 " translated_text = text.translate(unaccent_specials)\n",
36 " return unicodedata.normalize('NFKD', translated_text).\\\n",
37 " encode('ascii', 'ignore').\\\n",
49 "def only_lower(text):\n",
50 " return all((c in string.ascii_lowercase) for c in text)"
59 "# !find /usr -type f -iname 'british-english*'"
68 "# !ls -lah /usr/share/dict"
80 " return any(w in word \n",
81 " for w in 'piss shit cunt fuck arse crap fart jizz whore bitch'.split())"
97 "output_type": "execute_result"
106 "execution_count": 9,
112 "def words_with_len(n):\n",
113 " return [unaccent(w.strip()) for w in open('/usr/share/dict/british-english').readlines()\n",
114 " if only_lower(unaccent(w.strip()))\n",
115 " if len(unaccent(w.strip())) == n\n",
116 " if not rude(unaccent(w.strip()))]"
121 "execution_count": 10,
126 "output_type": "stream",
128 "4566 5-letter words\n",
129 "7223 6-letter words\n",
130 "9815 7-letter words\n",
131 "10328 8-letter words\n"
138 "for n in [5, 6, 7, 8]:\n",
139 " dicts[n] = words_with_len(n)\n",
140 " print('{} {}-letter words'.format(len(dicts[n]), n))\n",
141 " with open('words{}.txt'.format(n), 'w') as f:\n",
142 " f.write('\\n'.join(sorted(set(dicts[n]))))\n"
147 "execution_count": null,
157 "display_name": "Python 3",
158 "language": "python",
166 "file_extension": ".py",
167 "mimetype": "text/x-python",
169 "nbconvert_exporter": "python",
170 "pygments_lexer": "ipython3",