Advertisement
mbratanov

03. Team Lineup

Oct 19th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. def team_lineup(*args):
  2.     countries = {}
  3.     for player, country in args:
  4.         if country not in countries:
  5.             countries[country] = []
  6.         countries[country].append(player)
  7.  
  8.     result = ""
  9.     for country, players in sorted(countries.items(), key=lambda item: (-len(item[1]), item[0])):
  10.         result += f"{country}:\n"
  11.         for player in players:
  12.             result += f"  -{player}\n"
  13.  
  14.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement