프로그래머스
1. Python
def solution(scores):
answer = ''
n = len(scores)
average = []
for j in range(n):
max_idx = 0
min_idx = 0
max_keep = []
min_keep = []
total = 0
for i in range(n):
if scores[i][j] > scores[max_idx][j]:
max_idx = i
max_keep = []
elif scores[i][j] == scores[max_idx][j]:
max_idx = i
max_keep.append(max_idx)
max_keep.append(i)
if scores[i][j] < scores[min_idx][j]:
min_idx = i
min_keep = []
elif scores[i][j] == scores[min_idx][j]:
min_idx = i
min_keep.append(min_idx)
min_keep.append(i)
total += scores[i][j]
if max_idx == j and len(max_keep) < 2 or min_idx == j and len(min_keep) < 2:
average.append((total - scores[j][j]) / (n - 1))
else:
average.append(total / n)
for a in average:
if 90 <= a:
answer += 'A'
elif 80 <= a:
answer += 'B'
elif 70 <= a:
answer += 'C'
elif 50 <= a:
answer += 'D'
else:
answer += 'F'
print(average)
return answer
count 사용
def solution(scores) :
avgs=[]
score=[ [i[j] for i in scores] for j in range(len(scores))]
for idx,i in enumerate(score) :
avg=sum(i) ; length=len(i)
if i[idx] == max(i) or i[idx] == min(i) :
if i.count(i[idx]) == 1 :
avg-=i[idx] ; length-=1
avgs.append(avg/length)
return "".join([ avg>=90 and "A" or avg>=80 and "B" or avg>=70 and "C" or avg>=50 and "D" or "F" for avg in avgs ])