So I went down a rabbit hole with this one. At first I thought that enumerate is worse since in assembly, its a jmp and then iterating pointer and assigning vs just iterating and assigning. Turns out in newer version of Python they have made enumerate faster than reading and assigning!
Other languages actually have a numeric for loop, and not the odd range() thing. Don't get me wrong, python's for is good and works for everything, but this range() thing is weird
@@juliodonofreo I too was really frustrated with python's for loop in the beginning. But there's a way around it. For example writing something like, for i in range(1,10,2): print(i) Is the same as writing, for(int i=1;i
I've been coding python for more decades than I care to admit and if someone used the first two I wouldn't think they're "noobs", it's perfectly fine. Or conversely, that using the enumerate function is anything to show off about. The fact you think it's advanced says more about you than anything else.
Hey Tophat! I can appreciate your reaction. This short is just intended to be funny. I intentionally went over the top with the "noob" stuff just to make it more interesting in hopes that people would learn something new. Sorry if it came across too harsh.
@@robmulla Oh, now I feel mean! I obviously got the wrong end of the stick, apologies. Don't worry in the slightest, enumerate is a nice solid thing to teach learners for sure, very handy. If I'm honest, it's what I use by default.
Really? Youre going to shame people for using the "for i in range"? It is a core concept in Python, and does exactly what it needs to. Can you give a technical reason for *why* you shouldnt use "for i in range"?
There is none. He shows a solution to a different problem when you have a list of objects you want to iterate and do something with. His use case/example has nothing to do with it and is just slower
I'm a noob both in English and python but. Usually builtin functions in python are faster since they use lower level language. Thus when you use enumerate counters are being assigned in C. If you move this assignment into a python script by using variable inside the loop. You make it a tiny bit slower that cans tack for bigger lists. Same goes for len, you have to access index of the variable every time instead just getting it from the builtin function. And if you just need index and not content itself, you can always use throwaway variable "_"
I see you have spiced thing up come 2023. It is fun to watch. Love to see you work hard everyday with all the shorts and streams. I see that the freq of streams have increased. This motivates me to work harder! Thank you GM!!
As a C guy, I much prefer the "for .. in" construct. _Most_ use cases could just use the "for .. in" construct. Is it too much to ask for both the "for ( ; ; ) { }" _and_ the "for .. in" construct in the same language? That's what I'd like.
But why is it so much better? Does it help improve Data management? Is it faster? does it have any substantial advantege against just going through an Loop with the iterable Object range?
performance wise there doesn't seem to be much different, main advantages is its more explicit and shorter line wise, but these tend to minor concerns, it also has the advantage for working on iterables without indexes when that case comes up
It’s easier to work with, let’s say you want to access the index or use it to relate to some data inside a list or a dictionary, is easier to access it with enumerate.
yes. You have both the index and the iterated item. You don't have to worry about how to access the item with an index. It might also be faster too. Probably not though.
Enumerate looked so complicated to me at first when I was a total beginner. Now I kinda feel stupid, it's super easy. But feeling stupid is part of being a programmer I guess.
If your only goal was to take a list, give it indexes, and print it you could just do this: print(list(enumerate(todo_list))) You can lose the loop, it entails unnecessary overhead for loop control. You had unnecessary string manipulation with the call to the .title() which also cost time. The print function you use in the loop introduces overhead because of the underlying system calls it makes. Making multiple prints can be slower than a single print, especially if there's a lot of data to print.
Syntactic sugar is nice, but honestly, a simple loop counter, either manually or by means of the "for"-statement, is verbose and does not add a ton of clutter or overhead. If you actually need the counter and especially if you do maths with is, I feel a dedicated variable serves you much better.
Bro every type of these videos explaining how to do something a "better" way in code gets spammed with comments calling the creator of the video a clown 😭
I'l give you example. I had to hire two new junior devs as our team grew in past month or so. We had over 300 applicants and few of them had coding channels like these. Every single one was presenting themselves like seniors with 15 years of experience and weren't even able to write proper djisktra. You're better watching people like DavesGarage instead of pseudo-helpful channels like this.
Well... Under the hood it's basically doing the same thing. I suppose the code is more pythonic, but it only really improves readability if you're familiar with enumerate. Still a neat tip.
Learned this pretty early on, quite often though I wouldn’t care about the index, like your first print example, so it would have been cleaner and more straightforward to do it the “noob” way
I’m a senior python developer and at least in the finance industry there hasn’t even been a single situation where I would ever need to do something like this (btw I when I said finance I didn’t mean I work on THE actual finance systems but rather I work on a company within that industry as some sort of devops without the ops… but still doing CICD). Good to know this exists but I doubt not knowing this or doing one of the “noob” approaches will even get you fired in the real world
My code might not be efficient, looks like a three year old coded it. But you know what it works for what I want with it. And that in the end is what matters
Don’t be a noob, use a f-string, don’t be a noob don’t code in toy languages, code in c++, don’t be a noob code in C, don’t be a noob code in asm don’t be a noob code in binary
Me, the Haskell cultist: zip the entire stream of integers to the list, lift that function postcomposed with putStrLn, and then sequence/commutate the Traversable list with the Monad IO.
Well that is a built in function that can do that... but it is VERY slow in big lists, and can dramatically slow a program down with no clear sign of what is slowing things down
creating a range of length whatever does seem a little silly, but the counter solution is just as good as enumerate tbh. Also I wouldn't necessarily consider any approach a noob. if you're just iterating over a short list, its not a big deal how you manage it. I'll worry about code when it counts lol
You learn enumerate in your first programming course within the first 2 weeks. You can tell a real noob when they use enumerate for no reason and don't even use the indexes in their loop.
Something like that really depends. There is not right way to do something so modular like a loop. It all depends on your needs. If you need to repeat iterations, an approach like this would be the noob thing to do.
I'm used to programming in basic, without objects alright. Its a force of habit to say for i = 0 to 20, or in python, for i in range(20). I prefer direct access most of the time anyway
Enumerate is literally covered in the 3rd or 4th lecture in most Python for Humanities courses (I've taken one as a linguistics student back in the days, but I have seen the detailed curriculum for a bunch of others). Those courses teach you to make primitive scripts suitable for small data processing and nothing else. Knowledge of enumeration does not "un-noob" you anyhow 😂
I’m like 1 week into Python and I know about enumerate, I also know that for loops in Python are expensive af and a giveaway that you don’t give a shit about performance
ok so it adds the number, does it let you push that number to another function as well. and if so is it pushing the whole line as a string or as a int plus a string. vs a counter which you can just concat and print and then have both string and int. I wonder if my c background offers more precise code vs functions written for the smallest edge case
When you read the documentation once:
Who reads documentation? Kidding! You’re the real pro.
😯
I don't understand how people have difficulties understanding the documentation....
As long as you think, you are doing fine
But read the thing.
TempleOS is still superior.
thanks am going to read the docs
Ngl, calling people a noob is kinda a noob thing to do
yep, because he is also a noob who doesn’t even use List comprehension
I put dislike on both of your comments
Noob noob noob
@@the_w0nderful43 Okay. Have a nice day!
@@antonevstigneev846 why in ther world would he use a list comp here..? xd
Frankly, as long as you write clean, readable code, you're a pro to me, regardless of your knowledge of python's forensics. ❤️
That’s a fair take.
So I went down a rabbit hole with this one. At first I thought that enumerate is worse since in assembly, its a jmp and then iterating pointer and assigning vs just iterating and assigning. Turns out in newer version of Python they have made enumerate faster than reading and assigning!
@@wonderfulworldofmarkets9033Bro why’d you put yourself through that pain XD
yeah clean code makes a huge difference
@@geekzombie8795 Some people enjoy gaining knowledge, Brad.
The other two ways are perfectly acceptable in other languages and may even be easier to read so I have no issue with them.
Ok, you win! But now people know they all exist :D
Yeah honestly this is why I hate python 😂
Other languages actually have a numeric for loop, and not the odd range() thing. Don't get me wrong, python's for is good and works for everything, but this range() thing is weird
@@juliodonofreo I too was really frustrated with python's for loop in the beginning. But there's a way around it.
For example writing something like,
for i in range(1,10,2):
print(i)
Is the same as writing,
for(int i=1;i
I've been coding python for more decades than I care to admit and if someone used the first two I wouldn't think they're "noobs", it's perfectly fine. Or conversely, that using the enumerate function is anything to show off about.
The fact you think it's advanced says more about you than anything else.
Hey Tophat! I can appreciate your reaction. This short is just intended to be funny. I intentionally went over the top with the "noob" stuff just to make it more interesting in hopes that people would learn something new. Sorry if it came across too harsh.
@@robmulla Oh, now I feel mean! I obviously got the wrong end of the stick, apologies.
Don't worry in the slightest, enumerate is a nice solid thing to teach learners for sure, very handy. If I'm honest, it's what I use by default.
@@tophat593 most humble argument in the youtube comment section to date.
😊
@@jacckkaboii3528 true
meanwhile c/c++, c#, java, js and many others:
"iterating over a list? nah havent heard of it"
bro has never heard of a foreach loop 💀
Don't be a noob, don't code in python :)
checkmate!
I think we can spot the C♯/Java/PHP crowd, can’t we?
heyyyHEEYYYWHOAWHOAWHOA!
How long did it take you to code this comment?
Malboge is the only language for me.
Really? Youre going to shame people for using the "for i in range"?
It is a core concept in Python, and does exactly what it needs to. Can you give a technical reason for *why* you shouldnt use "for i in range"?
There is none. He shows a solution to a different problem when you have a list of objects you want to iterate and do something with. His use case/example has nothing to do with it and is just slower
NOOB!!
Jk I don't even code. I don't know why I'm here.
😂😂@@michaelbarker6460
the real noob thing would be to not mention why this would be better and why people should care
You’re right!
@@robmulla noob
I'm a noob both in English and python but. Usually builtin functions in python are faster since they use lower level language.
Thus when you use enumerate counters are being assigned in C. If you move this assignment into a python script by using variable inside the loop. You make it a tiny bit slower that cans tack for bigger lists.
Same goes for len, you have to access index of the variable every time instead just getting it from the builtin function.
And if you just need index and not content itself, you can always use throwaway variable "_"
Should i go for c or python i agree im a total noob but suggest me
@@shahidpathan9295 I've been coding for only like a month, but in my opinion you should learn Python before learning C
I see you have spiced thing up come 2023. It is fun to watch. Love to see you work hard everyday with all the shorts and streams. I see that the freq of streams have increased. This motivates me to work harder! Thank you GM!!
Thanks for watching. I tried to take a different “tone” in this video. I thought it was funny. Glad it motivates you! Keep working hard!
C language family devs: look at what they need to do to mimic a fraction of out power!
We only wish we in the python community had your power! 😂 luckily all the good python packages use C backend code.
As a C guy, I much prefer the "for .. in" construct. _Most_ use cases could just use the "for .. in" construct. Is it too much to ask for both the "for ( ; ; ) { }" _and_ the "for .. in" construct in the same language? That's what I'd like.
@@mage3690macro / ifdef
Then I am "Pro Noob", because I use any of these methods at will 😂😂😂
“Sorry the counter method is just because I’m so used to writing assembly in embedded systems, take that noob”
But why is it so much better?
Does it help improve Data management? Is it faster? does it have any substantial advantege against just going through an Loop with the iterable Object range?
performance wise there doesn't seem to be much different, main advantages is its more explicit and shorter line wise, but these tend to minor concerns, it also has the advantage for working on iterables without indexes when that case comes up
It’s easier to work with, let’s say you want to access the index or use it to relate to some data inside a list or a dictionary, is easier to access it with enumerate.
It's not better it likely works like the range does but looks "cleaner "
yes. You have both the index and the iterated item. You don't have to worry about how to access the item with an index.
It might also be faster too. Probably not though.
@@aocs13 you should not use indexes to access dictionary items. You should use the key. If the key is the index you should use a list.
Enumerate looked so complicated to me at first when I was a total beginner. Now I kinda feel stupid, it's super easy. But feeling stupid is part of being a programmer I guess.
No, you just stupid, I guess.
Kidding!
as a c++ user, i find it hard to believe this isn't common knowledge lmao
It is
It is common AF
@@smieszkipikczers1568 ur mom common af
hah. yea I guess we all have something to learn.
I'm really used to writing in c and c++, I didn't even knew of the enumerate function! Looks pretty handy
Glad you learned something!
Im just starting and I had to do something similar today for my work and this appears, thanks!
Glad it could help.
Me watching the video:
Doesn't enumerate come from itertools tho?
Me after a quick Google search:
Oh nice, it's a built-in function
Hey! You learned something. Nice.
**it doesnt say shit**
Enumerate is awesome but sometimes you really just need an index, and so range(len(Object)) works just fine
But you get the index with enumerate? or did i get this wrong?
Good point. There are many ways, true. Whatever suits your fancy!
@@msschubii guess if you are only using the index then enumerate is a waste of time because you only need the index, not the actual value
for i in enumerate(list):
........
@@Pilosofiano, that doesn't work iirc
If your only goal was to take a list, give it indexes, and print it you could just do this:
print(list(enumerate(todo_list)))
You can lose the loop, it entails unnecessary overhead for loop control. You had unnecessary string manipulation with the call to the .title() which also cost time. The print function you use in the loop introduces overhead because of the underlying system calls it makes. Making multiple prints can be slower than a single print, especially if there's a lot of data to print.
I am a noob. Still learning.
I am that double noob. I'm subscribing right away!
POV: U've learned a knew thing & excited 2 teach ppl abt it...
I found it like 3 or 2 weeks ago by mistake and it’s really nice function
love it!
When noobs tell noobs how to code:
I was literally writing code for this a minute ago, I go on shorts and I see my solution!
haha. I love that! But it's also a little bit scary.
Crazy co-incidence. I rarely code but had to do a few things and used this method noting it was different from the "counter" methods. Pretty cool.
python tips with davie504 style xD
SLAP LIKE NOW!
Syntactic sugar is nice, but honestly, a simple loop counter, either manually or by means of the "for"-statement, is verbose and does not add a ton of clutter or overhead. If you actually need the counter and especially if you do maths with is, I feel a dedicated variable serves you much better.
from double noob, to python pro just like that, oh boy what a day.
It’s almost too easy…
Hey man thanks for this! Helps make it a whole lot easier.
Thanks for the positive feedback. A lot of people seemed to miss the joke. The point was to teach something new.
Counters can be especially useful because they can be used to increment several variables at once.
Bro every type of these videos explaining how to do something a "better" way in code gets spammed with comments calling the creator of the video a clown 😭
Is that bad or good? I know it's good for engagement....
I'l give you example. I had to hire two new junior devs as our team grew in past month or so. We had over 300 applicants and few of them had coding channels like these. Every single one was presenting themselves like seniors with 15 years of experience and weren't even able to write proper djisktra.
You're better watching people like DavesGarage instead of pseudo-helpful channels like this.
@@robmulla it’s Bad if you have a community calling you a clown it’s good for short term engagement but horrible for long term engagement.
Well... Under the hood it's basically doing the same thing. I suppose the code is more pythonic, but it only really improves readability if you're familiar with enumerate. Still a neat tip.
Why did someone decide Python was necessary? lol.
I believe there are more than one way to achieve a result. You go with the one you're comfortable with.
This was literally the first thing I learnt when doing my python course.
Oh, I didn’t know Python was a real programming language 😂
Yea. That’s a different issue altogether 😊
It is not, it is just a wrapper. All heavy libraries are written in C anyway.
@@koleso1v blablabla
Im a week into my Python self learning - 90% of what he said was gibberish
I’ll eventually start it all 😂
Already knew it ❤ but still loved it
As soon as you said it I blurted out ENUMERATE, still watched to the end to see if you came up with something better tho lol
Glad there are multiple ways to do it.
as a machine learning engineer I see this as an absolute win, I think
Learned this pretty early on, quite often though I wouldn’t care about the index, like your first print example, so it would have been cleaner and more straightforward to do it the “noob” way
If you're incrementing a counter, odds are you just got done coding something in java or c
You're a true artist.
literally need this right now !
Loved the applied noob concept
As a noob myself I know a thing or two about it :D
I am certified noob.
Plot twist: I’m actually a triple noob….
I use all three sometimes. Video is meant to be in a joking manner. Hopefully it comes across that way 😂
"No, don't do this this way, we already have a built in function for ya"
I follow you 'cos you name and shame! 🤣🤣🤣I know I was under the table by the time you finished!
😶 I shame myself most!
I’m a senior python developer and at least in the finance industry there hasn’t even been a single situation where I would ever need to do something like this (btw I when I said finance I didn’t mean I work on THE actual finance systems but rather I work on a company within that industry as some sort of devops without the ops… but still doing CICD).
Good to know this exists but I doubt not knowing this or doing one of the “noob” approaches will even get you fired in the real world
Dead giveaway you’re a noob: using inbuilt functions for everything
I can’t even do the first and second yet, so I’m super noob !!! But now I know Enumerate !!
ultra pro!!
Ultra pro here😂❤
This helps me to remember functions.
My code might not be efficient, looks like a three year old coded it.
But you know what it works for what I want with it. And that in the end is what matters
I like this take. You do you! Video was meant to be funny and teach something new but I 100% agree with you.
I agree 100%
Don’t be a noob, use a f-string, don’t be a noob don’t code in toy languages, code in c++, don’t be a noob code in C, don’t be a noob code in asm don’t be a noob code in binary
01110101010101 01010101001010 1010100000010101 -> Sorry if the noob thing came off the wrong way, I was trying to make it over the top as a joke.
Why does he kinda sound like mordecai from regular show
My kids would love to hear that! lol
Yeah let me just call a function for every tiny thing in my programing life so I don't get called a noob in a UA-cam short.
Now you’re getting the idea!
I felt very attacked lol
Me: I am not noob 😃
He: DOUBLE NOOB!!!
I am a noob started learning python just for fun recently. Hope I can become a pro one day.
all pros start with printing 75 poop emojis
Me, the Haskell cultist: zip the entire stream of integers to the list, lift that function postcomposed with putStrLn, and then sequence/commutate the Traversable list with the Monad IO.
bro pissed so many people lmaoo
The funny thing is that in all the other languages I have used, the index variable is required in a for loop header
Well that is a built in function that can do that... but it is VERY slow in big lists, and can dramatically slow a program down with no clear sign of what is slowing things down
creating a range of length whatever does seem a little silly, but the counter solution is just as good as enumerate tbh.
Also I wouldn't necessarily consider any approach a noob. if you're just iterating over a short list, its not a big deal how you manage it. I'll worry about code when it counts lol
Literally every tutorial I've ever seen showed me the noob ways. 🤣😂🤣😂🤣
My tutorials have a lot of noob stuff in them too. Nobody is perfect!
My professor would flip if i used that.
As long as there isn't a difference in performance, I'll take easy to read code over pro code.
You do have a point there.
I like the way you did it
Thanks. I was trying to be a little funny in this video. Did you like the way I did the code or the video?
@@robmulla the video , it is funny and thanks for enumerate()
thumbs up for the san andreas bgm
You learn enumerate in your first programming course within the first 2 weeks. You can tell a real noob when they use enumerate for no reason and don't even use the indexes in their loop.
It’s a joke bruh 😂
Something like that really depends. There is not right way to do something so modular like a loop. It all depends on your needs. If you need to repeat iterations, an approach like this would be the noob thing to do.
Python is dope
That we can agree on.
I'm used to programming in basic, without objects alright. Its a force of habit to say for i = 0 to 20, or in python, for i in range(20). I prefer direct access most of the time anyway
Enumerate is literally covered in the 3rd or 4th lecture in most Python for Humanities courses (I've taken one as a linguistics student back in the days, but I have seen the detailed curriculum for a bunch of others). Those courses teach you to make primitive scripts suitable for small data processing and nothing else. Knowledge of enumeration does not "un-noob" you anyhow 😂
Heyy.... thanks for information
I am a beginner and a noob in the python language. I will be a pro pythonista someday.
I thought you were going to use the index lol
for things in mylist:
print(list.index(things), ',' ,things )
I am CERTIFIED GURU now!
Are we just gg to ignore the "eat brains" 😳 😳💀💀
Lol
You were the first one to catch it!
I honestly hate python for loops so much, why couldn't they leave it as C, java, etc for loops?
Interesting. What do you hate about them?
knew this from lua - for i,v in pairs(arr) do
I've always wanted to learn lua. What do you use it for?
when the teacher said no library 💀
I’m like 1 week into Python and I know about enumerate, I also know that for loops in Python are expensive af and a giveaway that you don’t give a shit about performance
Can you make dsa problem and solution video
I manually count them... without the scary snake 🐍
ummm. okay :D
N00b : Doing things the hard way!
Pro : just use built-in functions
Even better in a comprehension.
You google the right way to do it and take the first SO green check you see.
I know that exists in Lua/Luau (for i, v in ipairs(list)) but I didn't know you can do a similar thing in python
kinda like a for i,v in ipairs loop in lua
lua seems like a cool language. I know it's popular for scripting in game development, right?
@@robmulla yeah, and it's even simpler than python. it's used in roblox, don't starve, garry's mod, and a lot of other games for modding
Yea exactly
i read that as "be a python bro"
C programmer after watching this video(They just called noob):
ok so it adds the number, does it let you push that number to another function as well. and if so is it pushing the whole line as a string or as a int plus a string. vs a counter which you can just concat and print and then have both string and int. I wonder if my c background offers more precise code vs functions written for the smallest edge case
Not me over here using the zip function and range(len(list)) 😂