Skip to content

Commit 55bd5cf

Browse files
committed
feat: solve 34-enumerate
1 parent e4379b4 commit 55bd5cf

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

review/pb45/34.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
colors = ["red", "green", "black", "blue", "orange", "purple"]
2+
3+
dict1 = {}
4+
dict2 = {}
5+
for i, color in enumerate(colors):
6+
dict1[i] = color
7+
dict2[i + 100] = color
8+
9+
print(f"dict1 : {dict1} \n dict2 : {dict2}")
10+
11+
print("다른 방법")
12+
print(dict(enumerate(colors)))
13+
print(dict(enumerate(colors, 100)))
14+
15+
16+
# for문에서 index를 같이 활용하고 싶을때 enumerate() 를 사용할 수 있음
17+
# → enumerate() 는 열거형 객체를 반환하고 카운터 변수도 추가해줌
18+
# → enumerate(iterable, index의 시작값(기본값 0))

0 commit comments

Comments
 (0)