How to Use enumerate() in Python

  Рет қаралды 48,899

DataDaft

DataDaft

Күн бұрын

Пікірлер: 39
@DataDaft
@DataDaft 3 жыл бұрын
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
@bradyb2415 Жыл бұрын
character_map = {character: [i for i, char in enumerate(characters) if char == character] for character in set(characters)}
@malcolmx61
@malcolmx61 2 жыл бұрын
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!
@SpeaksYourWord
@SpeaksYourWord 2 жыл бұрын
And you'll always find this comment under every video
@Ligmamonkey
@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
@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.
@nicolenguyen8940
@nicolenguyen8940 3 жыл бұрын
i like the anime reference there
@dr_frankenmiller2607
@dr_frankenmiller2607 2 жыл бұрын
Always wondered what enumerate meant... thank you explaining that clearly. Yeah you're right I'll probly be using that all the time
@zufrankhan7793
@zufrankhan7793 2 жыл бұрын
I m exactly looking for this kind of video for enumerate fun. Thanks a lot
@yyanooo
@yyanooo 2 жыл бұрын
saved my life lol thank you . very straight to the point and concise !
@HARSHRAJ-2023
@HARSHRAJ-2023 3 жыл бұрын
Thank you so much. It was pretty helpful.
@dalton-ftt
@dalton-ftt 2 жыл бұрын
Great explanation and examples. Thank you.
@just_living_
@just_living_ Жыл бұрын
clean, simple and to the point ❤❤❤❤❤❤
@villagebakerystudio
@villagebakerystudio Жыл бұрын
Only video about enumarate() which can be found in youtube. Thank you very much..
@andreawu4547
@andreawu4547 2 жыл бұрын
short and sweet, i love it. thank you so much!!
@ninjapirate123
@ninjapirate123 8 ай бұрын
are u studying CS in college
@kychemclass5850
@kychemclass5850 Жыл бұрын
Very nice tutorial. Tq!!! :D
@aminrezaei1845
@aminrezaei1845 2 жыл бұрын
500th like is mine :) thanks pal.
@neuvocastezero1838
@neuvocastezero1838 3 ай бұрын
But, isn't the list already "enumerated"? Wouldn't for x in character: print(x, character[x]) provide the same information?
@MoHazem2002
@MoHazem2002 3 жыл бұрын
amzing simple explanataion!
@ultraman6950
@ultraman6950 3 жыл бұрын
Great job.
@lulprumpt4696
@lulprumpt4696 9 ай бұрын
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
@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.
@baharehizadpanah8233
@baharehizadpanah8233 2 жыл бұрын
It was really helpful, thank you
@38Fanda
@38Fanda 2 жыл бұрын
you should lift man, I recommend starting strength, alphadestiny, jason blaha & natural hypertrophy
@hashim1740
@hashim1740 2 жыл бұрын
in 4 minutes summarized what the lecturer has been trying to say in 50 minutes
@muhammadhamzashahid9649
@muhammadhamzashahid9649 3 жыл бұрын
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_turds
@Garth_turds 2 жыл бұрын
Great video!
@mumble_be9453
@mumble_be9453 2 жыл бұрын
Thank you!
@aurovindsahoo
@aurovindsahoo 10 ай бұрын
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
@ryanmanchikanti5265
@ryanmanchikanti5265 3 жыл бұрын
Could you please explain the term yield and how its used in python
@DataDaft
@DataDaft 3 жыл бұрын
Hey Ryan! Thanks for the idea. I'll consider that for a future video.
@Sam-wl4vo
@Sam-wl4vo Жыл бұрын
What's the name of the site he uses?
@beachwave5705
@beachwave5705 2 жыл бұрын
love the dbz reference
@chitkianchan1317
@chitkianchan1317 9 ай бұрын
what is character_map ?
@Howdidilose
@Howdidilose Жыл бұрын
🐐🐐
@the_hasnat
@the_hasnat Жыл бұрын
Thanks
@raylink1722
@raylink1722 4 ай бұрын
Allah bless you
@carlosprieto2554
@carlosprieto2554 3 жыл бұрын
te quiero
How to Make (Define) a Function in Python
5:26
DataDaft
Рет қаралды 37 М.
Using Python enumerate() With for Loops
14:01
Real Python
Рет қаралды 26 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Maha Marathon - Algorithm Part 1 | Khaleel Sir | GATE CSE 2025
4:03:46
GeeksforGeeks GATE
Рет қаралды 9 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Python dataclasses will save you HOURS, also featuring attrs
8:50
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 261 М.
How to Use Lists in Python
18:49
Programming with Mosh
Рет қаралды 333 М.
*Args and **Kwargs in Python
3:49
b001
Рет қаралды 296 М.
Enums Explained In Under 12 Minutes In Python
12:03
Indently
Рет қаралды 36 М.
Enumerate Will Save You From THIS!
4:01
John Watson Rooney
Рет қаралды 16 М.
How to Use Generator Expressions in Python
5:29
DataDaft
Рет қаралды 3,9 М.
List Comprehension - BEST Python feature !!! Fast and Efficient
14:51
Python Simplified
Рет қаралды 200 М.