-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathnames_set.py
42 lines (36 loc) · 1.08 KB
/
names_set.py
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
33
34
35
36
37
38
39
40
41
42
import sys
# handle command line arguments
# print useful message if no arguments given
if len(sys.argv) < 3:
print("Usage:")
print(" $ python3 names_set.py FEMALE_DATA MALE_DATA [TEST NAMES]")
print("Example:")
print(" $ python3 names_set.py dist.female.first dist.male.first Nick")
sys.exit()
# extract arguments from sys.argv
female_data = sys.argv[1]
male_data = sys.argv[2]
test_names = sys.argv[3:]
# Create sets for female and male names
female = set()
f = open(female_data)
for line in f:
female.add(line.split()[0])
f.close()
male = set()
f = open(male_data)
for line in f:
male.add(line.split()[0])
f.close()
# Summarize information about the reference data
print("There are {} female names and {} male names.".format(len(female),len(male)))
print("There are {} names that appear in both sets.".format(len(female & male)))
# Try our algorithm: note that it is biased!
for name in test_names:
if name.upper() in male:
ret = "M"
elif name.upper() in female:
ret = "F"
else:
ret = "NA"
print("{}: {}".format(name, ret))