Python:Библиотека/3/Модули/builtins/enumerate()
Материал из Онлайн справочника
Проверка/Оформление/Редактирование: Мякишев Е.А.
enumerate()
enumerate(iterable, start=0)
Параметры
iterable -
start -
Пример
№1
L = [i for i in range(1,50)]
print(L)
for i, num in enumerate(L):
if num % 2 == 0:
L[i] = num // 2
print(L)
Вывод:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
[1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49]
№2
Вывод:
См.также
Внешние ссылки