RUBY
리스트 pop() 함수(파이썬) 본문
pop() 함수
pop() 함수를 이용하면 마지막 인덱스에 해당하는 아이템을 삭제할 수 있다.
pop(n) 함수를 n인덱스에 해당하는 아이템을 삭제할 수 있다.
다음은 어떤 체조 선수의 점수표이다. 점수표에서 최고 및 최저 점수를 삭제해보자
playerScore = [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
maxScore = max(playerScore)
minScore = min(playerScore)
print("playerScore: {}".format(playerScore))
def minS(playerScore):
return list(filter(lambda x: x > min(playerScore), playerScore))
minScoreIdx = len(minS(playerScore)) -1
print("playerScore: {}".format(minS(playerScore)))
print("minScore: {}, minScoreIdx: {}".format(minScore, minScoreIdx))
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("maxScore: {}, maxScoreIdx: {}".format(maxScore, maxScoreIdx))
playerScore: [9.5, 8.9, 9.2, 9.8, 8.8, 9.0]
playerScore: [9.5, 8.9, 9.2, 9.8, 9.0]
minScore: 8.8, minScoreIdx: 4
playerScore: [9.5, 8.9, 9.2, 9.0]
maxScore: 9.8, maxScoreIdx: 3
'프로그래밍 언어 > Python' 카테고리의 다른 글
리스트 sort() 함수(파이썬) (0) | 2023.01.23 |
---|---|
리스트 extend() 함수 (파이썬) (0) | 2023.01.22 |
리스트 insert() 함수(파이썬) (0) | 2023.01.22 |
리스트 append() 함수(파이썬) (0) | 2023.01.22 |
리스트 enumerate()함수(파이썬) (1) | 2023.01.22 |
Comments