[Python] Randomly generate a large number of English names

Introduction

Sometimes I want a database with a big feeling for verification etc., but sometimes there are only a few records in the book / article sample. Then, let's make it for studying ... So, I made a name generation part.

What to prepare

We will borrow the original file from the repository of here. Place NamesDatabases / first names / us.txt and NamesDatabases / surnames / us.txt in the same folder. Since they have the same name, I changed them to ʻus_firstnames.txt and ʻus_lastnames.txt.

code

### import Modules
import random

### Preparation
#How many names to generate
NUMBER_OF_NAMES = 10000

# Reference:
# https://github.com/smashew/NameDatabases

### Main Code
f = open('us_firstnames.txt')
firstnameList = f.read().split('\n')
f.close()
f = open('us_lastnames.txt')
lastnameList = f.read().split('\n')
f.close()

for i in range(NUMBER_OF_NAMES):
    currentFirstnameNo = round(random.random() * len(firstnameList))
    currentLastnameNo = round(random.random() * len(lastnameList))
    print(firstnameList[currentFirstnameNo] + " " + lastnameList[currentLastnameNo])

It will appear in the console for the time being, so you can spit it out as it is or paste it into Excel (csv). Of course, feel free to do it in your code ...

Recommended Posts

[Python] Randomly generate a large number of English names
Executing a large number of Python3 Executor.submit may consume a lot of memory
Connect a large number of videos together!
ETL processing for a large number of GTFS Realtime files (Python edition)
python + faker Randomly generate a point with a radius of 100m from a certain point
Upload a large number of images to Wordpress
Organize a large number of files into folders
Accelerate a large number of simple queries with MySQL
[Python] A program that counts the number of valleys
Consolidate a large number of CSV files in folders with python (data without header)
Randomly generate a complete permutation
[Python] Etymology of python function names
Paste a large number of image files into PowerPoint [python-pptx]
Get the number of specific elements in a python list
Scrapy-Redis is recommended for crawling a large number of domains
Lambda + Python is good at restricting access with a large number of IP address lists
A record of patching a python package
[Python] I made a Line bot that randomly asks English words.
A good description of Python decorators
[Python] A memorandum of beautiful soup4
A brief summary of Python collections
Code to randomly generate a score
TensorFlow To learn from a large number of images ... ~ (almost) solution ~
Convert a large number of PDF files to text files using pdfminer
[Python] Generate a password with Slackbot
[Python] Correlation is below a certain level ・ Maximum number of features
Law of large numbers in python
Generate a list of consecutive characters
Generate a Python library download badge
Get the number of readers of a treatise on Mendeley in Python
[Python] A program that calculates the number of chocolate segments that meet the conditions
Get the number of searches with a regular expression. SeleniumBasic VBA Python
[Python] A program that calculates the number of socks to be paired
Generate a list packed with the number of days in the current month.
[Python] How to put any number of standard inputs in a list
Check the in-memory bytes of a floating point number float in Python
TensorFlow To learn from a large number of images ... (Unsolved problem) → 12/18 Solved
Maximum average number of daily visitors (large)
Make a relation diagram of Python module
[python] Get a list of instance variables
[python] [meta] Is the type of python a type?
Generate a class from a string in Python
The story of blackjack A processing (python)
[Python] Get a list of folders only
Project Euler # 17 "Number of Characters" in Python
A memorandum of python string deletion process
One-liner to create a large number of test files at once on Linux
[Python] A program that calculates the number of updates of the highest and lowest records
[Python] Plot data by prefecture on a map (number of cars owned nationwide)
A memo of a tutorial on running python on heroku
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Output the number of CPU cores in Python
Draw a graph of a quadratic function in Python
Convert "number" of excel date to python datetime
[python] Create a list of various character types
A memorandum of calling Python from Common Lisp
Calculate the total number of combinations with python
Make a copy of the list in Python
How to generate a Python object from JSON
Find the number of days in a month
Rewriting elements in a loop of lists (Python)