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)
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!
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.
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.
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
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
character_map = {character: [i for i, char in enumerate(characters) if char == character] for character in set(characters)}
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!
And you'll always find this comment under every video
i like the anime reference there
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.
Always wondered what enumerate meant... thank you explaining that clearly. Yeah you're right I'll probly be using that all the time
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.
I m exactly looking for this kind of video for enumerate fun. Thanks a lot
Thank you so much. It was pretty helpful.
saved my life lol thank you . very straight to the point and concise !
clean, simple and to the point ❤❤❤❤❤❤
Great explanation and examples. Thank you.
short and sweet, i love it. thank you so much!!
are u studying CS in college
in 4 minutes summarized what the lecturer has been trying to say in 50 minutes
amzing simple explanataion!
Very nice tutorial. Tq!!! :D
Great job.
Only video about enumarate() which can be found in youtube. Thank you very much..
500th like is mine :)
thanks pal.
But, isn't the list already "enumerated"? Wouldn't
for x in character:
print(x, character[x])
provide the same information?
Great video!
you should lift man, I recommend starting strength, alphadestiny, jason blaha & natural hypertrophy
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
It was really helpful, thank you
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.
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
Could you please explain the term yield and how its used in python
Hey Ryan! Thanks for the idea. I'll consider that for a future video.
Thank you!
love the dbz reference
What's the name of the site he uses?
what is character_map ?
🐐🐐
Thanks
Allah bless you
te quiero