반응형
SMALL
학생의 정보가 주어지고
그중에서 2번째로 작은 값을 찾아 출력
중첩이 되면 중복되는 값을 모두 출력 하는 문제 입니다.
if __name__ == '__main__': #기본 주어지는 코드
for _ in range(int(input())):
name = input()
score = float(input())
저는 고민하다 이렇게 풀었어요....
의미만 받아들여요
더보기
if __name__ == '__main__':
li = []
li_s = [] # li_score
for _ in range(int(input())):
name = input()
score = float(input())
li.append([name, score])
li_s.append(score)
li_s.sort() # li_score 정렬
a = li_s[0] # li_score 최소값
while a in li_s:
li_s.remove(a) # li_score 최소값 제거
a = li_s[0] # li_score에서 두번째로 작은 값은 a
li_n = [] # li_name
for li2 in li:
if li2[1] == a: # li[score]와 두번째로 작은 값 a 와 같으면
li_n.append(li2[0]) # li[name]을 li_name에 추가
li_n.sort() #li_name 정렬
for j in li_n:
print(j)
밑에는 다른 분
코드 짜신건데
제꺼와 느낌은 같지만,
깔끔하게 파이썬다움으로 코드를 짜셨음...
참고용 ㅜ
marksheet=[]
scorelist=[]
if __name__ == '__main__':
for _ in range(int(input())):
name = input()
score = float(input())
marksheet+=[[name,score]] #이름, 스코어 리스트 생성
scorelist+=[score] # 점수 리스트 생성
b=sorted(list(set(scorelist)))[1] # scorelist 내의 중복(set)을 없애고,
# list정려 시켜 [1] 번째를 b 로 지정
for a,c in sorted(marksheet): #marksheet[name,score]를 a,c 로
if c==b: # c (score) = b (두번째로 작은 수 )같으면
print(a) # a(name)을 출력
# 참고용으로 가지고 왔습니다....
#아직 많이 부족해서 예제를 두고 비교 하려고,...
반응형
LIST
'IT & 영상관련 > 파이썬python' 카테고리의 다른 글
python]hackerRank] lists (저장용) (0) | 2020.07.25 |
---|---|
python]hackerRank] Finding the percentage, 평균값(소수점)(저장용) (0) | 2020.07.24 |
python]hackerRank] Find the Runner-Up Score! 두번째 큰 수 찾기 (1) | 2020.07.22 |
python]hackerRank] List Comprehensions 리스트 이해 (0) | 2020.07.21 |
파이썬] 이분탐색 binary search (1) | 2020.07.06 |