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
Auf dieser Seite können Sie das Online-Video Python enumerate - a super helpful function to know mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer the bumbling biochemist 03 June 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,241 Mal angesehen und es wurde von 30 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!