첫 번째
def solution(answers):
students = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]
scores = {1: 0, 2: 0, 3: 0}
max_v = 0
for i in range(len(answers)):
for j in range(len(students)):
if answers[i] == students[j][i % len(students[j])]:
scores[j + 1] += 1
for k in range(1, len(scores) + 1):
if max_v <= scores[k]:
max_v = scores[k]
result = list(filter(lambda score: score[1] == max_v, scores.items()))
result = list(map(lambda score: score[0], result))
return result
수정 후
def solution(answers):
students = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]
scores = [0, 0, 0]
result = []
for idx, answer in enumerate(answers):
for i, a in enumerate(students):
if answer == a[idx % len(a)]:
scores[i] += 1
for idx, score in enumerate(scores):
if score == max(scores):
result.append(idx + 1)
return result
'코딩 기록장' 카테고리의 다른 글
python 3 : 프로그래머스 Level. 1 가운데 글자 가져오기 (0) | 2020.11.06 |
---|---|
python 3 : 프로그래머스 Level. 1 3진법 뒤집기 (0) | 2020.11.06 |
python 3 : 프로그래머스 Level. 1 2016년 (0) | 2020.11.06 |
python 3 : 프로그래머스 Level. 1 K번째 수 (0) | 2020.11.06 |
python 3 : 프로그래머스 Level. 1 체육복 (0) | 2020.11.06 |