]> projects.mako.cc - babynames_answers/blob - answer_3.py
b84ca860e73fd45deebe0df9f7ae77a9cb126279
[babynames_answers] / answer_3.py
1 # 3. What is the longest name in the dataset?
2
3 import ssadata
4
5 maximum_length = 0
6 longest_names = []
7
8 for boys_name in ssadata.boys.keys():
9     if len(boys_name ) > maximum_length:
10         maximum_length = len(boys_name)
11         longest_names = []
12         longest_names.append(boys_name)
13     elif len(boys_name) == maximum_length:
14         longest_names.append(boys_name)
15
16 for girls_name in ssadata.girls.keys():
17     if len(girls_name) > maximum_length:
18         maximum_length = len(girls_name)
19         longest_names = []
20         longest_names.append(girls_name)
21     elif len(girls_name) == maximum_length:
22         longest_names.append(girls_name)
23
24 print("The longest names in the data set are " + str(maximum_length) + " letters! They are:")
25
26 for name in longest_names:
27     print(name)
28
29

Benjamin Mako Hill || Want to submit a patch?