Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Archives
Today
Total
관리 메뉴

RUBY

튜플 정렬(파이썬) 본문

프로그래밍 언어/Python

튜플 정렬(파이썬)

ruby-jieun 2023. 1. 23. 02:09

 

 

 

튜플 정렬


 

 

 

튜플은 수정이 불가하기 때문에 리스트로 변환 후 정렬하자.

 

 

 

 

 

sort() 함수를 이용하면 아이템을 정렬할 수 있다.

 

 

 

 

 

sorted() 함수를 이용하면 튜플도 정렬할 수 있다

 

 

 

튜플로 정의된 점수표에서 최저 및 최고 점수를 삭제한 후 총점과 평균을 출력해 보자.

playerScore = (9.5, 8.9, 9.2, 9.8, 8.8, 9.0)
print('playerScore: {}'.format(playerScore))

playerScore = list(playerScore)
playerScore.sort()
print('playerScore: {}'.format(playerScore))

playerScore.pop(0)
playerScore.pop(len(playerScore) - 1)

playerScore = tuple(playerScore)
print('playerScore: {}'.format(playerScore))
playerScore: (9.5, 8.9, 9.2, 9.8, 8.8, 9.0)
playerScore: [8.8, 8.9, 9.0, 9.2, 9.5, 9.8]
playerScore: (8.9, 9.0, 9.2, 9.5)
Comments