프로그래밍 enumerate

  다른 뜻에 대해서는 영어 enumerate 문서를 참조하십시오.
enumerate

1 Python[ | ]

fruits = ['Apple', 'Banana', 'Mango']
print( type(enumerate(fruits) ))
print( dict(enumerate(fruits)) )
# <class 'enumerate'>
# {0: 'Apple', 1: 'Banana', 2: 'Mango'}
fruits = ['Apple', 'Banana', 'Mango']
for k, v in enumerate(fruits):
    print(k, v)
# 0 Apple
# 1 Banana
# 2 Mango
fruits = ['Apple', 'Banana', 'Mango']
for k in range( len(fruits) ):
    print(k, fruits[k])
# 0 Apple
# 1 Banana
# 2 Mango
fruits = ['Apple', 'Banana', 'Mango', 'Orange']
print(dict( enumerate(fruits, 1000) ))
# {1000: 'Apple', 1001: 'Banana', 1002: 'Mango', 1003: 'Orange'}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}