Initial import
This commit is contained in:
parent
42a5040008
commit
c5bb3b9d08
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright © 2022 Daniele Tricoli <eriol@mornie.org>
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar.
|
||||
# See http://www.wtfpl.net/ for more details.
|
||||
|
||||
"""
|
||||
Get all the words that ends with a specific substring.
|
||||
|
||||
An example written fast and in one go to reply to this toot¹ by
|
||||
@GustavinoBevilacqua@mastodon.cisti.org.
|
||||
|
||||
Date: 2023-01-07 16:37:58+01:00
|
||||
|
||||
¹ https://mastodon.cisti.org/@GustavinoBevilacqua/109638398244283183
|
||||
|
||||
"""
|
||||
|
||||
|
||||
italian_dict_path = "/usr/share/hunspell/it_IT.dic"
|
||||
|
||||
words = []
|
||||
|
||||
with open(italian_dict_path) as f:
|
||||
# skip first line: it's the number of words in the dict.
|
||||
next(f)
|
||||
|
||||
for line in f:
|
||||
|
||||
if line.startswith("/"):
|
||||
continue
|
||||
|
||||
word = line.split("/")[0].strip()
|
||||
words.append(word)
|
||||
|
||||
sorted_dict = sorted(words, key=lambda w: w[::-1])
|
||||
|
||||
word_end = "otte"
|
||||
rhymes = sorted([w for w in sorted_dict if w.endswith(word_end)])
|
Loading…
Reference in New Issue