]> projects.mako.cc - babynames_answers/blob - answer_6.py
4178dd02304903a9172c19ac5e001c5c4114bb0b
[babynames_answers] / answer_6.py
1 # 6. How many names are subsets of other names?
2 #
3 # Note: this problem gets really slow when you consider boys and girls names
4 # together. For simplicity, I'm treating them separately.
5
6 import ssadata
7
8 boysNamesSubsets = 0
9 for boysName in ssadata.boys.keys():
10     for otherBoysName in ssadata.boys.keys():
11         if boysName in otherBoysName and otherBoysName != boysName:
12             boysNamesSubsets = boysNamesSubsets + 1
13
14 girlsNamesSubsets = 0
15 for girlsName in ssadata.girls.keys():
16     for otherGirlsName in ssadata.girls.keys():
17         if girlsName in otherGirlsName and otherGirlsName != girlsName:
18             girlsNamesSubsets = girlsNamesSubsets + 1
19
20 print(str(boysNamesSubsets) + " boys names are subsets of other boys names.")
21 print(str(girlsNamesSubsets) + " girls names are subsets of other girls names.")
22

Benjamin Mako Hill || Want to submit a patch?