Skip to content

Instantly share code, notes, and snippets.

@Ellpeck
Last active July 20, 2022 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ellpeck/570c1c7deef7245f3e9824d906d5b3ab to your computer and use it in GitHub Desktop.
Save Ellpeck/570c1c7deef7245f3e9824d906d5b3ab to your computer and use it in GitHub Desktop.
from names_dataset import NameDataset
import json
nd = NameDataset()
firsts = []
lasts = []
countries = ["GB", "US", "FR", "DE", "PT", "ES", "NL", "IT", "MX", "CO", "ZA", "US"]
for country in countries:
print(country)
names = nd.get_top_names(n=1000, country_alpha2=country)
firsts.extend(names[country]["M"])
firsts.extend(names[country]["F"])
names = nd.get_top_names(n=2000, country_alpha2=country, use_first_names=False)
lasts.extend(names[country])
firsts = list(set(filter(lambda n: not " " in n, firsts)))
lasts = list(set(filter(lambda n: not " " in n, lasts)))
print(f"Found {len(firsts)} first names")
with open("first.json", "w", encoding="utf_8") as f:
f.write(json.dumps(firsts, ensure_ascii=False))
print(f"Found {len(lasts)} last names")
with open("last.json", "w", encoding="utf_8") as f:
f.write(json.dumps(lasts, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment