]> projects.mako.cc - babynames_answers/commitdiff
fixed a bug where this was counting every match, not every name that is a subset master
authorBenjamin Mako Hill <mako@atdot.cc>
Thu, 16 Apr 2015 06:11:36 +0000 (23:11 -0700)
committerBenjamin Mako Hill <mako@atdot.cc>
Thu, 16 Apr 2015 06:11:36 +0000 (23:11 -0700)
challenge_6.py

index 4178dd02304903a9172c19ac5e001c5c4114bb0b..20bc496ba3808802b5ff58a661744e72807369b7 100644 (file)
@@ -7,16 +7,21 @@ import ssadata
 
 boysNamesSubsets = 0
 for boysName in ssadata.boys.keys():
+    match = False
     for otherBoysName in ssadata.boys.keys():
-        if boysName in otherBoysName and otherBoysName != boysName:
+        if not match and boysName in otherBoysName and otherBoysName != boysName:
             boysNamesSubsets = boysNamesSubsets + 1
+            match = True
+
+print(str(boysNamesSubsets) + " boys names are subsets of other boys names.")
 
 girlsNamesSubsets = 0
 for girlsName in ssadata.girls.keys():
+    match = False
     for otherGirlsName in ssadata.girls.keys():
-        if girlsName in otherGirlsName and otherGirlsName != girlsName:
+        if not match and girlsName in otherGirlsName and otherGirlsName != girlsName:
             girlsNamesSubsets = girlsNamesSubsets + 1
+            match = True
 
-print(str(boysNamesSubsets) + " boys names are subsets of other boys names.")
 print(str(girlsNamesSubsets) + " girls names are subsets of other girls names.")
 

Benjamin Mako Hill || Want to submit a patch?