characters = ["Krillin","Goku", "Vegeta", "Gohan", "Piccolo"] # enumerate() returns a sequence of (index, item) tuples list(enumerate(characters)) # Use enumerate() in a for loop to get an item and its index for index, character in enumerate(characters): print(index, character) # Why might you want to use enumerate? # Example: store index positions of duplicate items characters = ["Krillin","Goku", "Goku", "Gohan", "Piccolo", "Krillin","Goku", "Vegeta", "Gohan", "Piccolo", "Piccolo","Goku", "Vegeta", "Goku", "Piccolo"] character_map = {character:[] for character in set(characters)} print(character_map) # Use enumerate to store the index for each occurence for index, character in enumerate(characters): character_map[character].append(index) character_map
@bradyb2415 Жыл бұрын
character_map = {character: [i for i, char in enumerate(characters) if char == character] for character in set(characters)}
@malcolmx612 жыл бұрын
I've been struggling understanding enumerate for a long time, other youtubers never explain what exactly enumerate does or how it works, they just skip right over it and use it, this video explained it perfectly, thank you!
@SpeaksYourWord2 жыл бұрын
And you'll always find this comment under every video
@Ligmamonkey Жыл бұрын
the comment "enumerate() returns a sequence of (index, item) tuples" really helped me out, for some reason all the explanations I was checking out didn't tell me what the hell it actually did, just the use cases.
@myyoutubeprofile-c3u Жыл бұрын
It's funny how python is supposed to be easier than C++ but as soon as you want to start doing something like this, C++ makes so much more sense.
@nicolenguyen89403 жыл бұрын
i like the anime reference there
@dr_frankenmiller26072 жыл бұрын
Always wondered what enumerate meant... thank you explaining that clearly. Yeah you're right I'll probly be using that all the time
@zufrankhan77932 жыл бұрын
I m exactly looking for this kind of video for enumerate fun. Thanks a lot
@yyanooo2 жыл бұрын
saved my life lol thank you . very straight to the point and concise !
@HARSHRAJ-20233 жыл бұрын
Thank you so much. It was pretty helpful.
@dalton-ftt2 жыл бұрын
Great explanation and examples. Thank you.
@just_living_ Жыл бұрын
clean, simple and to the point ❤❤❤❤❤❤
@villagebakerystudio Жыл бұрын
Only video about enumarate() which can be found in youtube. Thank you very much..
@andreawu45472 жыл бұрын
short and sweet, i love it. thank you so much!!
@ninjapirate1238 ай бұрын
are u studying CS in college
@kychemclass5850 Жыл бұрын
Very nice tutorial. Tq!!! :D
@aminrezaei18452 жыл бұрын
500th like is mine :) thanks pal.
@neuvocastezero18383 ай бұрын
But, isn't the list already "enumerated"? Wouldn't for x in character: print(x, character[x]) provide the same information?
@MoHazem20023 жыл бұрын
amzing simple explanataion!
@ultraman69503 жыл бұрын
Great job.
@lulprumpt46969 ай бұрын
man what i typed all this exactly and i get error unhashable type 'list' on the line using append...i googled and none of it makes sense
@sudhansumtripathy Жыл бұрын
when I enumerate , how is the character getting mapped , not able to understand this -- character_map[character].append(index), it read the character in characters and saved the items to characters_map, I am stuck at character_map[character] , [character ], how is it saving the the list.
@baharehizadpanah82332 жыл бұрын
It was really helpful, thank you
@38Fanda2 жыл бұрын
you should lift man, I recommend starting strength, alphadestiny, jason blaha & natural hypertrophy
@hashim17402 жыл бұрын
in 4 minutes summarized what the lecturer has been trying to say in 50 minutes
@muhammadhamzashahid96493 жыл бұрын
characters = ["Krillin","Goku", "Goku", "Gohan", "Piccolo", "Krillin","Goku", "Vegeta", "Gohan", "Piccolo", "Piccolo","Goku", "Vegeta", "Goku", "Piccolo"] character_map = {character:[] for character in set(characters)} for index, character in enumerate(characters): character_map[character].append(index) character_map
@Garth_turds2 жыл бұрын
Great video!
@mumble_be94532 жыл бұрын
Thank you!
@aurovindsahoo10 ай бұрын
Hi @Datadaft youyr videos are awesome but not well paced in your profile please arrange all in one group and share it like you can make all predefined function of python and keep it in 1 group
@ryanmanchikanti52653 жыл бұрын
Could you please explain the term yield and how its used in python
@DataDaft3 жыл бұрын
Hey Ryan! Thanks for the idea. I'll consider that for a future video.