Stop using range() for loops in Python. Use enumerate()

Опубликовано: 24 Январь 2020
на канале: Data Science Garage
2,576
42

With this video I explain why in many cases we should use enumerate() instead of range() function in Python for loops.

The way of using range() is ugly: You either need a separate variable assignment to get the element or use a[i] all the time which could theoretically be an expensive operation. The point is that you generally don't want to use range(len(l)) when you want to iterate the elements of a list (although there may still be cases where it makes sense).

I think than enumerate is much more flexible and readable Python coding option than len(l) with range().

Thank you for watching. See you on other tutorials.
Vytautas.

#pythonfunctions
#pythonloops
#pythonbegineers


Смотрите видео Stop using range() for loops in Python. Use enumerate() онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Data Science Garage 24 Январь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,576 раз и оно понравилось 42 людям.