enumerate
- "순서가 있는" 자료형에 대해서, 인덱스와 값을 포함해서 리턴해준다.
- 즉, 인덱스 & 값을 둘 다 사용하고 싶을 때 쓸 수 있다.
values = [40, 30, 20, 10, 50]
indexed_values = [(value, index) for index, value in enumerate(values)]
print(indexed_values)
print(indexed_values[1])
print(indexed_values[1][1])
# 출력
[(40, 0), (30, 1), (20, 2), (10, 3), (50, 4)]
(30, 1)
1
- 그러나 인덱스 값을 바꿀 순 없다.... indexed_values[1][1] = 10 이런거 불가능
반응형
'알고리즘 > 코테 개념, TIP, 메모' 카테고리의 다른 글
필독!!) DP (Dynamic Programming) (0) | 2024.07.29 |
---|---|
이진탐색 요약 (0) | 2024.07.29 |
필독!!) 백트래킹 요약 (0) | 2024.07.22 |
문제풀이 TIP (Test Case) (1) | 2024.07.22 |
필독!!) DFS / BFS 정리 + 인접행렬, 인접리스트 (2) | 2024.07.15 |