Ad
  • Custom User Avatar

    Well as the problem was just to return only one winner, I just evicted duplicates, which doesn't allow the other problem where you would want to return an ordered list of "winners" (?)
    If that was the case, I would obviously choose another method to keep my results ordered (maybe an OrderedDict like you did)

  • Custom User Avatar

    Sorry, I debuged with your source code.
    I realized setdefault is only one saved in dictionary.
    Yes. the other problem is exists.
    Original problem: return first player
    The other problem: return first, second player

    How about?
    In case

    print(winner([c16, c17, c18])) #Rob, Gandalf
    print(winner([c18, c17, c16])) #Gandalf, Rob
    
  • Custom User Avatar

    scores only store the first candidate for each total score when iterating candidates, which is ordered, and so the order is "preserved" as I evict all duplicates (look at the setdefault method usage)

    Maybe I shouldn't have used a dictionnary for this and just stored a winner variable updated when seeing a candidate with a better score, this would have been easier to read I think.

  • Custom User Avatar

    How about equal player??
    dictionary is not ordered.
    scores is dictionary that not ordered.