''' DS2000 Spring 2020 Source code from class: finding the winner of the caucus ''' def get_winner(candidates): ''' Function: get_winner Parameters: list of strings (candidate names, with pct won embedded as part of the same string, e.g., "warren.18.3") Returns: the name of the winner, a string ''' winner = "" winning_pct = -1 # iterate by value for candidate in candidates: pos = candidate.index(".") name = candidate[:pos] pct = float(candidate[pos + 1:]) if pct > winning_pct: winning_pct = pct winner = name return (winner, winning_pct)