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:04

 

 

리스트와 튜플 차이점


 

 

 

튜플은 리스트와 달리 아이템 추가, 변경, 삭제가 불가하다.

 

 

 

 

튜플은 선언 시 괄호 생략이 가능하다.

 

 

 

 

리스트와 튜플은 자료형 변환이 가능하다.

 

 

튜플을 이용한 점수표에서 최저 및 최고 점수를 삭제한 후 총점과 평균을 출력해 보자

playerScore = (9.5, 8.9, 9.2, 9.8, 8.8, 9.0)

print('playerScore: {}'.format(playerScore))

maxScore = max(playerScore)
minScore = min(playerScore)
print(type(playerScore))
def minS(playerScore):
    return list(filter(lambda x: x > min(playerScore), playerScore))
minScoreIdx = len(minS(playerScore)) -1

print("playerScore: {}".format(minS(playerScore)))

print(type(playerScore))
def maxS(playerScore):
    return list(filter(lambda y: min(playerScore) < y < max(playerScore), playerScore)) #최저점수만 삭제하고 싶으면 "min(playerScore) <" 부분을 제거
maxScoreIdx = len(maxS(playerScore)) -1

print("playerScore: {}".format(maxS(playerScore)))
print(type(playerScore))
sum = sum(maxS(playerScore))
avg = sum / len(maxS(playerScore))

print('총점: %.2f' %sum)
print('평점: %.2f' %avg)
playerScore: (9.5, 8.9, 9.2, 9.8, 8.8, 9.0)
<class 'tuple'>
playerScore: [9.5, 8.9, 9.2, 9.8, 9.0]
<class 'tuple'>
playerScore: [9.5, 8.9, 9.2, 9.0]
<class 'tuple'>
총점: 36.60
평점: 9.15

'프로그래밍 언어 > Python' 카테고리의 다른 글

튜플 for문을 이용한 조회(파이썬)  (0) 2023.01.23
튜플 정렬(파이썬)  (0) 2023.01.23
튜플 슬라이싱[n:m](파이썬)  (0) 2023.01.23
튜플 결합(파이썬)  (0) 2023.01.23
튜플 길이(파이썬)  (0) 2023.01.23
Comments