<jupyter_start><jupyter_text>2020년 6월 20일 토요일 HackerRank - Sorting : Comparator (Python) 문제 : https://www.hackerrank.com/challenges/ctci-comparator-sorting/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=sorting 블로그 : https://somjang.tistory.com/entry/HackerRank-Sorting-Comparator-Python  첫번째 시도<jupyter_code>from functools import cmp_to_key
class Player:
    def __init__(self, name, score):
        self.name = name
        self.score = score
        
    def __repr__(self):
        return "{} {}".format(self.name, self.score)
        
    def comparator(a, b):
        if a.score == b.score:
            if a.name > b.name:
                return 1
            else:
                return -1
        else:
            return b.score - a.score

n = int(input())
data = []
for i in range(n):
    name, score = input().split()
    score = int(score)
    player = Player(name, score)
    data.append(player)
    
data = sorted(data, key=cmp_to_key(Player.comparator))
for i in data:
    print(i.name, i.score)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12361623616236163, 'fraction_numerical': 0.011992619926199263, 'mean_word_length': 2.6655405405405403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '565905', 'license': 'MIT', 'n_tokens_mistral': 405, 'n_tokens_neox': 406, 'n_words': 75, 'path': 'DAY 101 ~ 200/DAY135_[HackerRank] Sorting Comparator (Python).ipynb', 'repo_name': 'SOMJANG/CODINGTEST_PRACTICE', 'size': '1084'}