Let me elaborate on why I love Python enumerate! It adds a counter to your for loop without you having to explicitly update the count/index each time. Which can save you a lot of time - and prevent a lot of silly coding errors!
blog: https://bit.ly/enumeratebb
Basically, a “for loop” is a coding thing where you tell the computer to go through some list of things and do something each time, such as printing out the thing. And with enumerate it will keep count as it goes. You can access that count by doing something like this:
for i, thing in things:
“i” will be the index and each time you go through, it will be updated
Like most things in Python, it will start at 0 by default (so i=0 for the first thing in the list). But you can specify the start value (just put “, start = “ to get it to start wherever you want.
I think it’s easiest to explain with examples, so hope this quick vid helps. I will also upload the code file if you want to look at the syntax and play around.
I’m definitely not a Python expert, but this is one of those fundamental Python functions that anyone who only tangentially uses Python should know. And for some reason it took me a while to find out about it. So I thought I’d introduce you if you weren’t familiar with it.
If you want more information, RealPython has a nice guide:
Python enumerate(): Simplify Looping With Counters by Bryan Weber: https://realpython.com/python-enumerate/
And here’s the official documentation for it: https://docs.python.org/3/library/fun...
It’s a built-in Python function so you don’t have to import anything. Just enjoy!
more coding-related videos: • coding stuff
more Python tips: https://bit.ly/bb_python_tips
more on why you should learn to code: https://bit.ly/why_program
Смотрите видео Python enumerate - a super helpful function to know онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь the bumbling biochemist 03 Июнь 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,241 раз и оно понравилось 30 людям.