From 3254131f8ec1f5a9978dea4c576c728d29e0d147 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Wed, 15 Apr 2015 23:11:36 -0700 Subject: [PATCH 1/1] fixed a bug where this was counting every match, not every name that is a subset --- challenge_6.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/challenge_6.py b/challenge_6.py index 4178dd0..20bc496 100644 --- a/challenge_6.py +++ b/challenge_6.py @@ -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.") -- 2.39.5