Given the data set, a specific year, and a sex, I need to report the most popula
ID: 3551407 • Letter: G
Question
Given the data set, a specific year, and a sex, I need to report the most popular name for that year and sex.
So first off, the program will ask you to insert the year that the user is interested in, then ask the gender that the user is interested in, and print out the most popular names corresponding to the year and gender. FYI, the number on the right represents how many people share that name in that column, so the most popular name would be the one with the biggest number. Thank you!
2007 AALIYAH F 138 2007 AARON M 459 2007 ABBY F 16 2007 ABDULLAH M 26 2007 ABIGAIL F 692 2007 ABRAHAM M 178 2007 ADAM M 371 2007 ADDISON F 193 2007 ADEN M 10 2007 ADINA F 11 2007 ADONIS M 12 2007 ADRIAN M 262 2007 ADRIANA F 180 2007 ADRIANNA F 119 2007 AHARON M 9 2007 AHMED M 22 2007 AIDAN M 579 2007 AIDEN M 616Explanation / Answer
//Test run with year = 2008 and gender = 'F': http://ideone.com/FdbLyudata = [(2007, 'AALIYAH', 'F', 138), (2007, 'AARON', 'M', 459), (2007, 'ABBY', 'F', 16), (2007, 'ABDULLAH', 'M', 26), (2007, 'ABIGAIL', 'F', 692), (2007, 'ABRAHAM', 'M', 178), (2007, 'ADAM', 'M', 371), (2007, 'ADDISON', 'F', 193), (2007, 'ADEN', 'M', 10), (2007, 'ADINA', 'F', 11), (2007, 'ADONIS', 'M', 12), (2007, 'ADRIAN', 'M', 262), (2007, 'ADRIANA', 'F', 180), (2007, 'ADRIANNA', 'F', 119), (2007, 'AHARON', 'M', 9), (2007, 'AHMED', 'M', 22), (2007, 'AIDAN', 'M', 579), (2007, 'AIDEN', 'M', 616), (2008, 'JADE', 'F', 137), (2008, 'JADEN', 'M', 287), (2008, 'JADIEL', 'M', 12), (2008, 'JAEDEN', 'M', 15), (2008, 'JAELYN', 'F', 8), (2008, 'JAHDIEL', 'M', 5), (2008, 'JAIDEN', 'M', 145), (2008, 'JAIME', 'M', 17), (2008, 'JAKE', 'M', 369), (2008, 'JAKOB', 'M', 5), (2008, 'JAKUB', 'M', 26), (2008, 'JALEN', 'M', 13), (2008, 'JAMAL', 'M', 11), (2008, 'JAMARI', 'M', 13), (2008, 'JAMES', 'M', 878), (2008, 'JAMIE', 'F', 45), (2008, 'JANE', 'F', 11), (2008, 'JANELLE', 'F', 26), (2008, 'JANIAH', 'F', 11), (2008, 'JANICE', 'F', 13), (2008, 'JANIYA', 'F', 20), (2008, 'JANIYAH', 'F', 22), (2008, 'JARED', 'M', 92), (2008, 'JARIEL', 'M', 22), (2009, 'BRIANNA', 'F', 506), (2009, 'BRIDGET', 'F', 24), (2009, 'BRIELLE', 'F', 40), (2009, 'BRODY', 'M', 90), (2009, 'BROOKE', 'F', 233), (2009, 'BROOKLYN', 'F', 19), (2009, 'BRUCE', 'M', 5), (2009, 'BRUCHA', 'F', 19), (2009, 'BRYAN', 'M', 279), (2009, 'BRYANT', 'M', 32), (2009, 'BRYCE', 'M', 69), (2009, 'BRYNN', 'F', 19), (2009, 'BYRON', 'M', 15), (2009, 'CADEN', 'M', 55), (2009, 'CADENCE', 'F', 9), (2009, 'CAIDEN', 'M', 13), (2009, 'CAITLIN', 'F', 50), (2009, 'CAITLYN', 'F', 20), (2009, 'CALEB', 'M', 275), (2009, 'CALVIN', 'M', 11),]year = int(input('Enter year: '))gender = input('Enter gender: ').upper()## The 'pythonic' way'''import operators = max([t for t in data if t[0]==year and t[2]==gender], # list of tuple with corresponding year and gender key=operator.itemgetter(3)) # find max with key = t[3] which is the last columngender = 'boy' if gender=='M' else 'girl' # just for pretty printprint('The most popular {1} name in year {0} is {2}'.format(year, gender, s[1]))'''## The 'unpythonic' waytmax = ()for t in data: if t[0]==year and t[2]==gender: if len(tmax) == 0: tmax = t elif tmax[-1]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.