from typing import List, Tuple def topScorer(data: str) -> str | None: """Return the name(s) of the student(s) with the highest total score.""" lines = [line for line in map(lambda line: line.strip(), data.split("\n")) if line] max_score: List[Tuple[str, int]] = [] for line in lines: name, *scores = line.split(",") scores = list(map(int, scores)) if not scores: max_score.append((name, 0)) else: max_score.append((name, sum(scores))) max_score.sort(key=lambda x: x[1], reverse=True) if not max_score: return None names = [name for name, score in max_score if score == max_score[0][1]] return ",".join(names) print("Testing topScorer()...", end="") data = """\ Joe,10,20,30,40 Lauren,10,20,30 Ben,10,20,30,5 """ assert topScorer(data) == "Joe" data = """\ David,11,20,30 Austin,10,20,30,1 Lauren,50 """ assert topScorer(data) == "David,Austin" data = """\ Ping-Ya,100,80,90 """ assert topScorer(data) == "Ping-Ya" data = """\ Reyna,20,40,40 Ema,5,5,5,5,10 Ketandu,50,20,10,20 Tanya,80,20 Kate,70 """ assert topScorer(data) == "Reyna,Ketandu,Tanya" assert topScorer("") == None print("Passed!")