bisect
: 정렬되어 있는 리스트에서 정렬을 흩트리지 않아도 되는 부분의 '인덱스'를 엄청 빠른 속도로 찾아주는 모듈
bisect_left(literable, value) : 왼쪽 인덱스를 구하기
bisect_right(literable, value) : 오른쪽 인덱스를 구하기 (bisect = bisect_right)
from bisect import bisect_left, bisect_right
nums = [0,1,2,3,4,5,6,7,8,9]
n = 5
print(bisect_left(nums, n))
print(bisect_right(nums, n))
'''
결과값
5
6
'''
출처: https://programming119.tistory.com/196 [개발자 아저씨들 힘을모아:티스토리]
'코딩테스트 > Python 개념' 카테고리의 다른 글
| [python] f-string (5) | 2025.06.09 |
|---|---|
| [Python] 백트래킹 주의사항 (1) | 2024.10.07 |
| [Python] 리스트 숫자 값을 한 글자씩 문자열로 나누기 (0) | 2024.10.01 |
| [Python] map 으로 list 내 값 하나하나에 함수 적용하기 (0) | 2024.06.21 |
| [Python] deque의 최대 길이 설정 deque(iterable, maxlen) (0) | 2024.06.20 |