Тёмный

Be a Python Pro with Enumerate 

Rob Mulla
Подписаться 172 тыс.
Просмотров 989 тыс.
50% 1

Enumerate is an important built in function in #python and #coding folks should know how to use it. Don't be a noob!

Опубликовано:

 

16 янв 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 917   
@jan0195
@jan0195 Год назад
When you read the documentation once:
@robmulla
@robmulla Год назад
Who reads documentation? Kidding! You’re the real pro.
@samueljehanno
@samueljehanno Год назад
😯
@MemesterTheMaster
@MemesterTheMaster Год назад
I don't understand how people have difficulties understanding the documentation.... As long as you think, you are doing fine But read the thing.
@GetOffMyPhoneGoogle
@GetOffMyPhoneGoogle Год назад
TempleOS is still superior.
@originalbinaryhustler3876
@originalbinaryhustler3876 Год назад
thanks am going to read the docs
@jackmillen
@jackmillen Год назад
Ngl, calling people a noob is kinda a noob thing to do
@antonevstigneev846
@antonevstigneev846 Год назад
yep, because he is also a noob who doesn’t even use List comprehension
@the_w0nderful43
@the_w0nderful43 Год назад
I put dislike on both of your comments
@the_w0nderful43
@the_w0nderful43 Год назад
Noob noob noob
@jackmillen
@jackmillen Год назад
@@the_w0nderful43 Okay. Have a nice day!
@mettwasser
@mettwasser Год назад
​@@antonevstigneev846 why in ther world would he use a list comp here..? xd
@5cover
@5cover Год назад
Frankly, as long as you write clean, readable code, you're a pro to me, regardless of your knowledge of python's forensics. ❤️
@robmulla
@robmulla Год назад
That’s a fair take.
@wonderfulworldofmarkets9033
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!
@kevinwoodrobotics
@kevinwoodrobotics 6 месяцев назад
yeah clean code makes a huge difference
@Haja024
@Haja024 Месяц назад
​@@geekzombie8795 Some people enjoy gaining knowledge, Brad.
@dallin5861
@dallin5861 Год назад
The other two ways are perfectly acceptable in other languages and may even be easier to read so I have no issue with them.
@robmulla
@robmulla Год назад
Ok, you win! But now people know they all exist :D
@derickd6150
@derickd6150 6 месяцев назад
Yeah honestly this is why I hate python 😂
@juliodonofreo
@juliodonofreo 5 месяцев назад
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
@specter538
@specter538 3 месяца назад
​@@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
@tegathemenace
@tegathemenace 20 дней назад
​@@specter538 in their heads it's shorter😂. Anything to stay unique I guess
@tophat593
@tophat593 Год назад
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.
@robmulla
@robmulla Год назад
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.
@tophat593
@tophat593 Год назад
@@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.
@jacckkaboii3528
@jacckkaboii3528 Год назад
@@tophat593 most humble argument in the youtube comment section to date.
@mast3rvnzla
@mast3rvnzla Год назад
😊
@lucasalvarani1724
@lucasalvarani1724 Год назад
​@@jacckkaboii3528 true
@SlyceDFI
@SlyceDFI 3 месяца назад
meanwhile c/c++, c#, java, js and many others: "iterating over a list? nah havent heard of it"
@koam_
@koam_ Месяц назад
bro has never heard of a foreach loop 💀
@gandalfthegrey2777
@gandalfthegrey2777 8 дней назад
Bro
@TheVergile
@TheVergile Год назад
the real noob thing would be to not mention why this would be better and why people should care
@robmulla
@robmulla Год назад
You’re right!
@bobby9192
@bobby9192 Год назад
@@robmulla noob
@xsardas1999
@xsardas1999 5 месяцев назад
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 "_"
@shahidpathan9295
@shahidpathan9295 5 месяцев назад
Should i go for c or python i agree im a total noob but suggest me
@lpalaguachi2
@lpalaguachi2 4 месяца назад
​@@shahidpathan9295 I've been coding for only like a month, but in my opinion you should learn Python before learning C
@blaze_eagle
@blaze_eagle Год назад
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?
@moonlightaria968
@moonlightaria968 Год назад
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
@aocs13
@aocs13 11 месяцев назад
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.
@Beeftitan
@Beeftitan 11 месяцев назад
It's not better it likely works like the range does but looks "cleaner "
@lucaxtshotting2378
@lucaxtshotting2378 6 месяцев назад
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.
@lucaxtshotting2378
@lucaxtshotting2378 6 месяцев назад
@@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.
@eugenex8892
@eugenex8892 Год назад
Don't be a noob, don't code in python :)
@robmulla
@robmulla Год назад
checkmate!
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Год назад
I think we can spot the C♯/Java/PHP crowd, can’t we?
@nathanaelmccooeye3204
@nathanaelmccooeye3204 Год назад
heyyyHEEYYYWHOAWHOAWHOA!
@JimMaz
@JimMaz Год назад
How long did it take you to code this comment?
@marktuggle5609
@marktuggle5609 Год назад
Malboge is the only language for me.
@JoeBob189
@JoeBob189 Месяц назад
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"?
@skylo706
@skylo706 Месяц назад
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
@michaelbarker6460
@michaelbarker6460 Месяц назад
NOOB!! Jk I don't even code. I don't know why I'm here.
@andrewtate8792
@andrewtate8792 25 дней назад
😂😂​@@michaelbarker6460
@gandalfthegrey2777
@gandalfthegrey2777 8 дней назад
​@@skylo706nah what he did is exactly what you do with i in range Entire video is just satire
@Adomas_B
@Adomas_B Год назад
C language family devs: look at what they need to do to mimic a fraction of out power!
@robmulla
@robmulla Год назад
We only wish we in the python community had your power! 😂 luckily all the good python packages use C backend code.
@mage3690
@mage3690 6 месяцев назад
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.
@Abraham_doestech
@Abraham_doestech 5 месяцев назад
​@@mage3690macro / ifdef
@MrCaturday
@MrCaturday Год назад
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.
@monolith757
@monolith757 Год назад
No, you just stupid, I guess. Kidding!
@user-bg1xh3yl5o
@user-bg1xh3yl5o Год назад
as a c++ user, i find it hard to believe this isn't common knowledge lmao
@818de60
@818de60 Год назад
It is
@smieszkipikczers1568
@smieszkipikczers1568 Год назад
It is common AF
@818de60
@818de60 Год назад
@@smieszkipikczers1568 ur mom common af
@robmulla
@robmulla Год назад
hah. yea I guess we all have something to learn.
@KeepCalmCapybara
@KeepCalmCapybara Месяц назад
Then I am "Pro Noob", because I use any of these methods at will 😂😂😂
@nirbhay_raghav
@nirbhay_raghav Год назад
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!!
@robmulla
@robmulla Год назад
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!
@fingerman4086
@fingerman4086 Год назад
Enumerate is awesome but sometimes you really just need an index, and so range(len(Object)) works just fine
@msschubi
@msschubi Год назад
But you get the index with enumerate? or did i get this wrong?
@robmulla
@robmulla Год назад
Good point. There are many ways, true. Whatever suits your fancy!
@kingoreo7050
@kingoreo7050 Год назад
@@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
@Pilosofia
@Pilosofia Год назад
for i in enumerate(list): ........
@blackscrow
@blackscrow Год назад
​@@Pilosofiano, that doesn't work iirc
@unhhgcrxexhjvuvujchcrzwzwz7956
@unhhgcrxexhjvuvujchcrzwzwz7956 4 месяца назад
“Sorry the counter method is just because I’m so used to writing assembly in embedded systems, take that noob”
@llambduh
@llambduh 8 месяцев назад
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.
@Alee_Calee
@Alee_Calee 19 дней назад
This was really helpful for my 5th grade python on-paper test, thx!
@christophercarillo4784
@christophercarillo4784 Год назад
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
@robmulla
@robmulla Год назад
Hey! You learned something. Nice.
@anubhav9476
@anubhav9476 Год назад
python tips with davie504 style xD
@robmulla
@robmulla Год назад
SLAP LIKE NOW!
@adrisongomez6482
@adrisongomez6482 Год назад
I found it like 3 or 2 weeks ago by mistake and it’s really nice function
@robmulla
@robmulla Год назад
love it!
@Michael-ty2uo
@Michael-ty2uo Год назад
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 😭
@robmulla
@robmulla Год назад
Is that bad or good? I know it's good for engagement....
@faremir
@faremir 6 месяцев назад
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.
@Michael-ty2uo
@Michael-ty2uo 6 месяцев назад
@@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.
@pastori2672
@pastori2672 Месяц назад
**it doesnt say shit**
@godbernaz
@godbernaz Год назад
Im just starting and I had to do something similar today for my work and this appears, thanks!
@robmulla
@robmulla Год назад
Glad it could help.
@hidden_leafy
@hidden_leafy Год назад
I thought you were going to use the index lol for things in mylist: print(list.index(things), ',' ,things )
@Ironpecker
@Ironpecker Год назад
I'm really used to writing in c and c++, I didn't even knew of the enumerate function! Looks pretty handy
@robmulla
@robmulla Год назад
Glad you learned something!
@Viii498
@Viii498 Год назад
Oh, I didn’t know Python was a real programming language 😂
@robmulla
@robmulla Год назад
Yea. That’s a different issue altogether 😊
@koleso1v
@koleso1v Год назад
It is not, it is just a wrapper. All heavy libraries are written in C anyway.
@Skaffa
@Skaffa Год назад
@@koleso1v blablabla
@skylo706
@skylo706 Месяц назад
When noobs tell noobs how to code:
@CodingCorvus
@CodingCorvus Год назад
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
@robmulla
@robmulla Год назад
I like this take. You do you! Video was meant to be funny and teach something new but I 100% agree with you.
@pfuhad3760
@pfuhad3760 Год назад
I agree 100%
@jamil1985
@jamil1985 Месяц назад
I am a noob. Still learning.
@ExceededTag6048
@ExceededTag6048 Год назад
I was literally writing code for this a minute ago, I go on shorts and I see my solution!
@robmulla
@robmulla Год назад
haha. I love that! But it's also a little bit scary.
@prashlovessamosa
@prashlovessamosa Год назад
I am certified noob.
@robmulla
@robmulla Год назад
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 😂
@GottZ
@GottZ Год назад
fun fact about enumerate.. it's essentially a counter so it's equal to the double noob solution.
@fluffden
@fluffden Год назад
from double noob, to python pro just like that, oh boy what a day.
@robmulla
@robmulla Год назад
It’s almost too easy…
@AyatExplorer
@AyatExplorer 27 дней назад
POV: U've learned a knew thing & excited 2 teach ppl abt it...
@MercuryShore
@MercuryShore Год назад
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 RU-vid short.
@robmulla
@robmulla Год назад
Now you’re getting the idea!
@Kumar-oe9jm
@Kumar-oe9jm Год назад
Are we just gg to ignore the "eat brains" 😳 😳💀💀
@testtester3249
@testtester3249 Год назад
Lol
@robmulla
@robmulla Год назад
You were the first one to catch it!
@Znwarp
@Znwarp Год назад
If you're incrementing a counter, odds are you just got done coding something in java or c
@mikelk124
@mikelk124 Год назад
Counters can be especially useful because they can be used to increment several variables at once.
@AlphaChinou
@AlphaChinou Год назад
Python is dope
@robmulla
@robmulla Год назад
That we can agree on.
@Chronologist89
@Chronologist89 Год назад
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.
@IHyperspaceI
@IHyperspaceI Год назад
The funny thing is that in all the other languages I have used, the index variable is required in a for loop header
@Rajarikamvamshi
@Rajarikamvamshi Год назад
If you think, doing this make you expert then you are certified noob!
@robmulla
@robmulla Год назад
Then a noob I am! 😊
@Rajarikamvamshi
@Rajarikamvamshi 10 месяцев назад
Same here
@bucketzzz.
@bucketzzz. Год назад
Hey man thanks for this! Helps make it a whole lot easier.
@robmulla
@robmulla Год назад
Thanks for the positive feedback. A lot of people seemed to miss the joke. The point was to teach something new.
@Sauvenil
@Sauvenil Год назад
Why did someone decide Python was necessary? lol.
@andrewhabroad
@andrewhabroad Год назад
Now build it in c++
@robmulla
@robmulla Год назад
😶
@ivanichianus
@ivanichianus Год назад
Im a week into my Python self learning - 90% of what he said was gibberish I’ll eventually start it all 😂
@topazadam
@topazadam Год назад
This was literally the first thing I learnt when doing my python course.
@TeddyFitz
@TeddyFitz 11 месяцев назад
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.
@iuk4280
@iuk4280 Год назад
This helps me to remember functions.
@bumbalaaa
@bumbalaaa Год назад
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
@devanshjaiswal9502
@devanshjaiswal9502 Месяц назад
I am that double noob. I'm subscribing right away!
@crazyclassicalkim
@crazyclassicalkim 4 месяца назад
Me: I am not noob 😃 He: DOUBLE NOOB!!!
@emmywraps7165
@emmywraps7165 Год назад
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
@robmulla
@robmulla Год назад
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.
@viktorhugo1715
@viktorhugo1715 5 месяцев назад
"No, don't do this this way, we already have a built in function for ya"
@simon2112
@simon2112 Год назад
I honestly hate python for loops so much, why couldn't they leave it as C, java, etc for loops?
@robmulla
@robmulla Год назад
Interesting. What do you hate about them?
@moth_la
@moth_la 5 месяцев назад
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.
@iuritorres
@iuritorres Год назад
wait wait waiiit, then we can use index and value of array itens in the same scope??? broo that's insane, thank u!
@2mellow35
@2mellow35 6 месяцев назад
My professor would flip if i used that.
@temie933
@temie933 2 месяца назад
Dead giveaway you’re a noob: using inbuilt functions for everything
@g1tr3kt5
@g1tr3kt5 Год назад
Literally every tutorial I've ever seen showed me the noob ways. 🤣😂🤣😂🤣
@robmulla
@robmulla Год назад
My tutorials have a lot of noob stuff in them too. Nobody is perfect!
@KevinArellano
@KevinArellano Год назад
I manually count them... without the scary snake 🐍
@robmulla
@robmulla Год назад
ummm. okay :D
@user-iz7kw1si2e
@user-iz7kw1si2e 6 дней назад
Thanks! U remember me about enumerate function❤
@cobsidian7843
@cobsidian7843 7 месяцев назад
N00b : Doing things the hard way! Pro : just use built-in functions
@willykitheka7618
@willykitheka7618 Год назад
I follow you 'cos you name and shame! 🤣🤣🤣I know I was under the table by the time you finished!
@robmulla
@robmulla Год назад
😶 I shame myself most!
@fitnessjournal5554
@fitnessjournal5554 Год назад
I can’t even do the first and second yet, so I’m super noob !!! But now I know Enumerate !!
@robmulla
@robmulla Год назад
ultra pro!!
@tech-learner4555
@tech-learner4555 11 месяцев назад
​Ultra pro here😂❤
@michaelOgunjimi
@michaelOgunjimi 11 месяцев назад
I believe there are more than one way to achieve a result. You go with the one you're comfortable with.
@igors634
@igors634 День назад
Learning control flow in any language is prerequisite calling yourself a noob)
@fee-f1-foe-fum
@fee-f1-foe-fum Год назад
I was waiting for the list comprehension 😢
@robmulla
@robmulla Год назад
I put a video out about it.
@Shake_Well_Before_Use
@Shake_Well_Before_Use 11 месяцев назад
as a machine learning engineer I see this as an absolute win, I think
@torinmorris6648
@torinmorris6648 Год назад
I would like to hear one good reason to not continue the i in range(len(list)): list[i] format.
@robmulla
@robmulla Год назад
This article has a few reasons: themeptation.medium.com/why-use-enumerate-instead-of-range-in-your-pythons-loops-d33bfd9c7531
@Money_2030
@Money_2030 Год назад
A medium article 💀💀
@vaishakhgk2006
@vaishakhgk2006 Год назад
@@Money_2030 It gets the job done, but not very pythonic. You have to get the length of the list to keep track of the index, then index into the array to get the current fruit - which makes the code more verbose and harder to read. This was the reason in the article😅😂
@victoriathomas4674
@victoriathomas4674 Год назад
Why does he kinda sound like mordecai from regular show
@robmulla
@robmulla Год назад
My kids would love to hear that! lol
@wassupbaby8634
@wassupbaby8634 6 месяцев назад
Glad there are multiple ways to do it.
@lucaskeyworth
@lucaskeyworth Год назад
knew this from lua - for i,v in pairs(arr) do
@robmulla
@robmulla Год назад
I've always wanted to learn lua. What do you use it for?
@mparkourmaster7747
@mparkourmaster7747 Месяц назад
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
@MonicaRamirez-pf6xr
@MonicaRamirez-pf6xr 8 месяцев назад
I felt very attacked lol
@poryg5350
@poryg5350 Год назад
As long as there isn't a difference in performance, I'll take easy to read code over pro code.
@robmulla
@robmulla Год назад
You do have a point there.
@jayco10125
@jayco10125 28 дней назад
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
@BobChess
@BobChess 4 месяца назад
C programmer after watching this video(They just called noob):
@SabertoothTypewriter
@SabertoothTypewriter Год назад
"python is the JavaScript of programming languages"
@robmulla
@robmulla Год назад
lol. What?
@cabudagavin3896
@cabudagavin3896 Год назад
wata roast edit: I agree with Sherlock, stop calling us noobs...
@davidbadea1360
@davidbadea1360 Год назад
I use the counter method but with a O = 0 and I actually felt good about it until now
@renatocorreaarrieche
@renatocorreaarrieche Год назад
Loved the applied noob concept
@robmulla
@robmulla Год назад
As a noob myself I know a thing or two about it :D
@MarineAquariumNovice
@MarineAquariumNovice 6 месяцев назад
Not me over here using the zip function and range(len(list)) 😂
@hypatia-du-bois-marie
@hypatia-du-bois-marie 9 месяцев назад
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.
@epsi
@epsi Год назад
Funny enough, i almost always want the list index (or dict key) because i'm modifying the stored values in some way or another, and the value originally stored is still accessible using the variable containing the second value yielded by enumerate(): # In-place equivalent of # slist = [s.title() for s in slist] # because doubling memory costs # doesn't scale for huge lists. for i, s in enumerate(slist): slist[i] = s.title() Maybe that's why Go always provides the index/key when ranging over a slice/map (list/dict in Python)?
@poopfartlord9695
@poopfartlord9695 Год назад
Or you're not a noob because you're coming from an actual programming language that isn't as amazingly nice and friendly to use as python is.
@robmulla
@robmulla Год назад
You got me! 😃
@mnsic2284
@mnsic2284 Год назад
I noob python cause I already used 2 of noob type in company product and it's work perfectly :))
@robmulla
@robmulla Год назад
I'm a noob too because I often forget to use enumerate or am too lazy to change old code. haha. The noob thing is just a joke to keep people's attention.
@user-dj3ty6th6r
@user-dj3ty6th6r Месяц назад
Oh noooo, i already upload my code using those double noob method😂
@MustaphaRashiduddin-zx7rn
@MustaphaRashiduddin-zx7rn 8 месяцев назад
i read that as "be a python bro"
@victorescobar7437
@victorescobar7437 Год назад
If you need a counter, does this method also count? I know the list will have a length but just wondering.
@epsi
@epsi Год назад
enumerate() is a generator that yields a 2-tuple containing a counter and a value. >>> pows2 = [2**p for p in range(8)] >>> for i, x in enumerate(pows2): . . . print(i, x) . . . 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 As you can see, the first item in the tuple generated by enumerate() can function as a simple counter. You can also pass a _start_ keyword argument to start the counter at a value other than 0, but iteration stops after all items in an iterable have been enumerated.
@_-tg-_
@_-tg-_ Год назад
... and with the start parameter, we can decide the starting index :)
@robmulla
@robmulla Год назад
I didn’t know about that… you my friend are a certified ULTRA PRO.
@webberdontstarve7017
@webberdontstarve7017 Год назад
kinda like a for i,v in ipairs loop in lua
@robmulla
@robmulla Год назад
lua seems like a cool language. I know it's popular for scripting in game development, right?
@webberdontstarve7017
@webberdontstarve7017 Год назад
@@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
@colin1444
@colin1444 Год назад
Yea exactly
@yesseruser
@yesseruser 4 месяца назад
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
@tygret
@tygret Год назад
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.
@robmulla
@robmulla Год назад
It’s a joke bruh 😂
@RemcoPeggeman
@RemcoPeggeman 6 месяцев назад
It seems like enumerate will create a new list and duplicate the contents of the original. Then you loop over it and do whatever. You just increased the amount of memory used and made two loops instead of one. In the context of an actual program that probably doesn’t matter but without any given non-functional requirements it’s quite noobish to call this a noob-move. Maybe the list is huuuge and then this is a noob move.
@wiktorwrona9416
@wiktorwrona9416 5 месяцев назад
No, enumerate returns an enumerate object which is an Iterator, it does not create a new list nor it requires any significant memory compared to the size of list(basically its almost free operation, memory wise).
@Sweaty_-
@Sweaty_- Год назад
Am currently learning python and I feel bad as f for barely understanding anything u said ):
@gsg9704
@gsg9704 Год назад
I get that this is supposed to be ina fun format.. but the for loop with range funct seemed just as compact and efficient to me. Is there any advantage to the enumerate method I'm missing?? or, does it really look more pro? haha I wouldn't want to come off as a certified noob!
@robmulla
@robmulla Год назад
Enumerate is built by the python devs for this specific case. So to not use it would kind of go against the language. But at the same time, sometimes you just gotta do you.
@orcishman27
@orcishman27 Год назад
For some case better loop using range. Rather than for data in list
@hideakikovacs2859
@hideakikovacs2859 7 месяцев назад
when the teacher said no library 💀
Далее
The Truth About Learning Python in 2024
9:38
Просмотров 135 тыс.
How I would learn to code (If I could start over)
9:16
Sinfdosh xotin 7😂
01:01
Просмотров 2 млн
5 Good Python Habits
17:35
Просмотров 398 тыс.
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Просмотров 849 тыс.
Functions in Python are easy 📞
10:38
Просмотров 405 тыс.
Learn Python by Building a Snake Game under 10 minutes
7:16
5 Useful F-String Tricks In Python
10:02
Просмотров 268 тыс.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Please Master These 10 Python Functions…
22:17
Просмотров 62 тыс.
C++ Developer Learns Python
9:26
Просмотров 2,7 млн
I tried 10 code editors
10:28
Просмотров 2,9 млн
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1,1 млн