So I have tuple in a list in two places
group_a = [(“Yellow”,200),(“Red”,450),(“Pink”,320)] group_b = [(“Blue”,350),(“Green”,590),(“Purple”,190)]
I’d like to unpack this two groups with def function and return the teams that have the highest scores and also return the group the highest score was found in.
def highest_scores(group_a,group_b):
best_team = “”
best_score = 0
winner = “”
for team,score in group_a and group_b:
if score > best_score:
best_team = team
best_score = score
winner = best_team,best_score in group_a or group_b
else:
pass
print(“Congratulations!”)
return (best_team,best_score,winner)
highest_scores(group_a,group_b)
Congratulations! (‘Green’, 590, (‘Green’, [(‘Blue’,350),(‘Green’,590), (‘Purple’,190)]))
So I got the best team and best score just like I wanted but I also got the list of the group the highest scores was found in instead of just the group name (group_b) Also, is there another way to do this with less lines of codes using def function?
I hope I made this as clear as possible Thank you