def solution(participant, completion):
answer = ''
temp = 0
dic = {}
for part in participant:
dic[hash(part)] = part
temp += int(hash(part))
for com in completion:
temp -= hash(com)
# 유일하게 하나의 멤버만 존재하므로 가능한 방법인듯...!
answer = dic[temp]
return answer
⭐ collections 클래스의 Counter 메서드 사용법
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
# print(collections.Counter(participant))
# print(collections.Counter(completion))
# print(This is hash of my key : answer)
return list(answer.keys())[0]
str = "This is my key!!"
key = hash(str)
print(key)
----------------------------
출력 :
3117656213745715764
❓Hash값으로 어떻게 만들까
print(collections.Counter(participant))
print(collections.Counter(completion))
print(answer)
------------------------------------------
출력 :
Counter({'leo': 1, 'kiki': 1, 'eden': 1})
Counter({'eden': 1, 'kiki': 1})
Counter({'leo': 1})