1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| from functools import reduce def solution(participant, completion): participant_dic = reduce(lambda dic, ch: dic.update({ch: dic.get(ch, 0)+1}) or dic, participant, {}) completion_dic = reduce(lambda dic, ch: dic.update({ch:dic.get(ch,0)+1}) or dic, completion, {}) for key, value in participant_dic.items(): if completion_dic.get(key, 0) == 0: answer = key return answer elif participant_dic[key] != completion_dic[key]: answer = key return answer
from collections import Counter def solution(participant, completion): answer = Counter(participant) - Counter(completion) return list(answer.keys())[0]
def solution(participant, completion): participant.sort() completion.sort() for i in range(len(completion)): if participant[i] != completion[i]: return participant[i] return participant[len(participant)-1]
def solution(participant, completion): participant.sort() completion.sort() for p, c in zip(participant, completion): if p != c: return p return participant[-1]
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
if __name__ == "__main__": participant = ["mislav", "stanko", "ana", "mislav", "jonus"] completion = ["stanko", "ana", "mislav", "jonus"] ret = solution(participant, completion) print(ret)
|