상세 컨텐츠

본문 제목

enumerate 사용법

카테고리 없음

by bumychoi 2024. 7. 8. 22:39

본문

i=["Rad","Green","Black","Blue","Orange","Purple"]

#1
o2=dict(zip(range(len(i)),i))
print(o2)

#2
o1=dict(enumerate(i))
print(o1)

#3
o3 =dict(enumerate(i,start=100))
print(o3)

 

 

{0: 'Rad', 1: 'Green', 2: 'Black', 3: 'Blue', 4: 'Orange', 5: 'Purple'}
{0: 'Rad', 1: 'Green', 2: 'Black', 3: 'Blue', 4: 'Orange', 5: 'Purple'}

82102@LAPTOP-Q74SBCUO MINGW64 ~/Desktop/python_basic_1.5
$ C:/Users/82102/AppData/Local/Programs/Python/Python311/python.exe c:/Users/82102/Desktop/python_basic_1.5/ex/ex34.py
{0: 'Rad', 1: 'Green', 2: 'Black', 3: 'Blue', 4: 'Orange', 5: 'Purple'}
{0: 'Rad', 1: 'Green', 2: 'Black', 3: 'Blue', 4: 'Orange', 5: 'Purple'}
{100: 'Rad', 101: 'Green', 102: 'Black', 103: 'Blue', 104: 'Orange', 105: 'Purple'}