Advertisement
DiYane

Race

Sep 27th, 2023
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import re
  2.  
  3. name_of_participants = {name.replace(" ", ""): 0 for name in input().split(",")}
  4. racer_code = input()
  5. letters_d = re.compile(r"([A-Za-z])")
  6. numbers_d = re.compile(r"([0-9])")
  7. while racer_code != "end of race":
  8.     find_name = "".join(re.findall(letters_d, racer_code))
  9.     find_numbers = sum(int(num) for num in re.findall(numbers_d, racer_code))
  10.     if find_name in name_of_participants.keys():
  11.         name_of_participants[find_name] += find_numbers
  12.     racer_code = input()
  13.  
  14. name_of_participants = sorted(name_of_participants.items(), key=lambda x: -x[1])
  15.  
  16. print(f"1st place: {name_of_participants[0][0]}")
  17. print(f"2nd place: {name_of_participants[1][0]}")
  18. print(f"3rd place: {name_of_participants[2][0]}")
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement