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.
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
.
### 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