Last active
May 19, 2023 16:50
-
-
Save D1360-64RC14/ac018f8a26eae81f27ad4cf4de5dcae1 to your computer and use it in GitHub Desktop.
IA name filter. Code for https://gist.github.com/D1360-64RC14/9f80884a6ed68daf945c1b1305780b52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
NAME = 0 | |
FREQUENCY = 1 | |
file = open("nomes.csv", "r") | |
name_reader = csv.DictReader(file) | |
# CATIA -> CatIA | |
def IAlize(name): | |
name = name.capitalize().removesuffix("ia") | |
return name + "IA" | |
ia_names_freqs = [] | |
for row in name_reader: | |
# Separate | |
name = row["first_name"] | |
freq = int(row["frequency_total"]) | |
# Filter | |
if (not name.endswith("IA")): continue | |
# Transform | |
ia_name = IAlize(name) | |
ia_names_freqs.append((ia_name, freq)) | |
ia_names_freqs.sort(key=lambda nf: nf[FREQUENCY], reverse=True) | |
ia_names = list(map(lambda nf: nf[NAME], ia_names_freqs)) | |
print("\n".join(ia_names)) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment