Python for Absolute Beginners Transcripts
Chapter: Cleaner code with common data structures
Lecture: Concept: Data structures simplify our code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that data structures dramatically
0:02 simplify our code.
0:04 Earlier, we had those really complicated checks
0:06 to juggle all the different things that we were doing.
0:09 And our dog, it wasn't happy.
0:10 This dog, this is a happy dog
0:12 this is a dog that loves clean code, I guess.
0:14 So, one example was we wanted to track the wins
0:18 without having player_1 wins
0:20 and then all the player_2 wins
0:21 and then if player_1 wins matches this
0:24 then player_1 value and all this other weirdness.
0:27 So we were able to just create a dictionary called Wins
0:30 and have the name of the players as the keys
0:32 and the values start out at zero and then we increment them
0:35 and then, to find the winner, we just say
0:36 How many rounds are we playing? 3?
0:40 go through each name to see if any of them
0:42 are high enough if they've won, then you'll return that
0:45 otherwise, nobody's currently won.
0:47 And all you got to do to find who's currently won
0:49 its either no one or one of the two players
0:51 is pass the win, no wins above, or the player name.
0:55 Really really nice way to keep track of
0:58 linked data together using this data structure.
1:02 There's a lot of stuff that we've done with dictionaries.
1:04 In this chapter, yeah, they are really really powerful
1:07 they're probably the second-most important data structure.
1:10 First one, of course, is lists.
1:12 And we'll talk about those a little bit as well.
1:14 But in this case, it was the dictionary that we needed.
1:17 How do you know a dictionary?
1:19 You going to use a list?
1:20 Well, we'll get into that in a minute.
1:21 But think this code is dramatically better
1:24 than what we started with.