Skip to content

Instantly share code, notes, and snippets.

@D1360-64RC14
Last active May 19, 2023 16:50
Show Gist options
  • Save D1360-64RC14/ac018f8a26eae81f27ad4cf4de5dcae1 to your computer and use it in GitHub Desktop.
Save D1360-64RC14/ac018f8a26eae81f27ad4cf4de5dcae1 to your computer and use it in GitHub Desktop.
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