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 simplify our code. Earlier, we had those really complicated checks
0:07 to juggle all the different things that we were doing. And our dog, it wasn't happy. This dog, this is a happy dog
0:13 this is a dog that loves clean code, I guess. So, one example was we wanted to track the wins without having player_1 wins
0:21 and then all the player_2 wins and then if player_1 wins matches this then player_1 value and all this other weirdness.
0:28 So we were able to just create a dictionary called Wins and have the name of the players as the keys
0:33 and the values start out at zero and then we increment them and then, to find the winner, we just say How many rounds are we playing? 3?
0:41 go through each name to see if any of them are high enough if they've won, then you'll return that otherwise, nobody's currently won.
0:48 And all you got to do to find who's currently won its either no one or one of the two players is pass the win, no wins above, or the player name.
0:56 Really really nice way to keep track of linked data together using this data structure. There's a lot of stuff that we've done with dictionaries.
1:05 In this chapter, yeah, they are really really powerful they're probably the second-most important data structure. First one, of course, is lists.
1:13 And we'll talk about those a little bit as well. But in this case, it was the dictionary that we needed. How do you know a dictionary?
1:20 You going to use a list? Well, we'll get into that in a minute. But think this code is dramatically better than what we started with.

Talk Python's Mastodon Michael Kennedy's Mastodon