Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- votes = ["ABC","ACB","ABC","ACB","ACB"]
- 1st Post ->
- A -> 5
- B -> 2
- C -> 3
- D -> 0
- A -> []
- B -> []
- """
- from collections import defaultdict
- class Solution:
- def rankTeams(self, votes: list[str]) -> str:
- ranking = defaultdict(lambda: [0 for x in range(len(votes[0]))])
- for vote in votes:
- for index, c in enumerate(vote):
- ranking[c][index] -= 1
- sorted_teams = sorted(ranking.items(), key=lambda item: (item[1], item[0]))
- print(sorted_teams)
- return "".join(x for x,_ in sorted_teams)
- def rankTeams1(self, votes: list[str]) -> str:
- ranking = defaultdict(lambda: [0 for _ in range(len(votes[0]))])
- for vote in votes:
- for index, c in enumerate(vote):
- ranking[c][index] += 1
- sorted_teams = sorted(ranking.keys())
- print(sorted_teams)
- return "".join(sorted(sorted_teams, key=lambda x: ranking[x], reverse=True))
- # def testing(self):
- # c = "c"
- # c
- sol = Solution()
- votes1 = ["ABC","ACB","ABC","ACB","ACB"]
- votes2 = ["BCA","CAB","CBA","ABC","ACB","BAC"]
- print(sol.rankTeams1(votes2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement