def solution(scores):
student_score = []
grade = []
for i in range(len(scores)):
for j in range(len(scores)):
student_score.append(scores[j][i])
# 본인 점수
check_score = student_score[i]
# 조건
if (student_score.count(max(student_score)) == 1) and (check_score == max(student_score)):
student_score.remove(check_score)
if (student_score.count(min(student_score)) == 1) and (check_score == min(student_score)):
student_score.remove(check_score)
# 평균 구하기
student_avg = sum(student_score) / len(student_score)
# 학점 부여하기
if student_avg >= 90:
grade.append('A')
elif 80 <= student_avg < 90:
grade.append('B')
elif 70 <= student_avg < 80:
grade.append('C')
elif 50 <= student_avg < 70:
grade.append('D')
else:
grade.append('F')
student_score = []
return "".join(grade)
다른 사람 풀이 보면서 알게된 코드
조건문
a = [ avg>=90 and "A" or avg>=80 and "B" or avg>=70 and "C" or avg>=50 and "D" or "F" for avg in student_avg ]
행과 열 전환
scores = list(map(list, zip(*scores)))
문제
- 문자열로 구성된 리스트 strings와, 정수 n이 주어졌을 때, 각 문자열의 인덱스 n번째 글자를 기준으로 오름차순 정렬하려 합니다.
- 예를 들어 strings가 ["sun", "bed", "car"]이고 n이 1이면 각 단어의 인덱스 1의 문자 "u", "e", "a"로 strings를 정렬합니다.
def solution(string, n):
string.sort(key = lambda string : (string[n], string))
return string