-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_processing.py
More file actions
32 lines (24 loc) · 1.07 KB
/
input_processing.py
File metadata and controls
32 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import csv
def create_files():
male_names = []
female_names = []
# Read in all the names in the data set
for year in range (1880, 2017):
with open('input/names/yob' + str(year) + '.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
name = row[0].lower()
if row[1] == 'M':
male_names.append(name)
else:
female_names.append(name)
# Convert names to a set to preserve only unique entries
male_names = set(male_names)
female_names = set(female_names)
# Output the names to text files, separated by \n
with open('input/male_names.txt', mode='wt', encoding='utf-8') as male_file:
male_file.write('\n'.join(male_names))
with open('input/female_names.txt', mode='wt', encoding='utf-8') as female_file:
female_file.write('\n'.join(female_names))
print("We have a list of " + str(len(male_names)) + " male names and " + str(len(female_names)) + " female names.")
create_files()