1

I am having trouble with sorting this array to get the highest total amount of points and with the name next to it.

For entering the events its:

Flag = True
while Flag:
    try:
        e = str(input("Enter Event names [Type XXX to stop]: "))
        if e == 'XXX':
            Flag = False
        else:
            event.append(e)
    except ValueError:
        print("Please enter a word, Thanks")
print()

For entering house names its:

Flag = True
while Flag:
    try:
        h = str(input("Eneter House names [Type XXX to stop]: "))
        if h == 'XXX':
            Flag = False
        else:
            total = total + 1
            house.append(h)
    except ValueError:
        print("Please enter a word, Thanks")
print()

For then getting the points for events and house as follows:

for i in (event):
    for j in (house):
        Flag = True
        while Flag:
            try:
                sevent = int(input("Enter %s's house for %s score: "%(j, i)))
                if sevent < 0:
                    print("Enter a number above 0, Thanks")
                else:
                    Flag = False
            except ValueError:
                print("Please enter a number above, Thanks")
        if j not in scores:
            scores[j] = []
        scores[j].append(sevent)
        score.append(sevent)
        s_house = (j), (sevent)
        s_house_event.append(s_house)
        Flag = True
    s_h_and_e = (i), (s_house_event)
    list1.append(s_h_and_e)

As an example for when the output of the program as follows:

{'House 3': [2, 3, 4], 'House 2': [7, 7, 5], 'House1': [4, 4, 2]}

I am having trouble getting the House with the highest total sum of the points and printing an overall winner.

Thanks for anyone who can help.

1 Answer 1

1
max(scores, key=lambda h: sum(scores[h]))
# => 'House 2'
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer for getting the highest string, value would it be possible to get the sum of that highest string value points and also get the average for all houses points? And would it be possible to get the winner of each event? Thanks for the help
It is possible, but... honestly, you should be able to deduce an answer for those yourself by applying the insight from this answer. In particular, "sum of that highest string value points" is already answered inside this answer. See statistics.mean for average, or you can simply divide the sum by number of elements.
Thanks for your help man! I'll make yours the answer and close the thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.