728x90
01. 리스트 내포
- 실행 시간이 줄어듦
02. 리스트 내포를 이용하지 않은 경우
%%timeit
##Jupyter notebook에서만 제공, 셀 실행 시간을 계산
result1 = []
for num in range(10):
result1.append(num * 3)
# print(result1)
475 ns ± 7.15 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
03. 리스트 내포를 이용한 경우
%%timeit
result2 = [num * 3 for num in range(10)]
# print(result2)
370 ns ± 3.04 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
result = [num * 3 for num in range(10) if num % 2 == 0]
print(result)
[0, 6, 12, 18, 24]728x90
'01_Python' 카테고리의 다른 글
| 41_함수 (0) | 2025.01.08 |
|---|---|
| 40_제어문>제어문연습(2) (0) | 2025.01.08 |
| 38_제어문>enumerate함수 (0) | 2025.01.08 |
| 37_제어문>for반복문과 딕셔너리 조합 (0) | 2025.01.08 |
| 36_제어문>제어문 연습(1) (2) | 2025.01.07 |