Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Store the Winners as Values

00:00 Currently, you are printing index and spaceship inside of the for loop in each step. But instead, we want to put the spaceship name at the key with the same value as the index has right now into the winners dictionary.

00:15 So let’s change the print() function call in line 18 to captains and then a square bracket. And now the key should be the index.

00:29 So this will be 1, 2, or 3 is equal to spaceship,

00:36 and that sets the spaceship name for the keys 1, 2, 3.

00:42 Now you can basically move the print() function call of line 13 where you print the winners dictionary down below after the for loop

00:55 to verify that actually the items were added to the winners dictionary. And now I can see, I actually didn’t use the winners dictionary, but the captains dictionary, which would cause an error.

01:07 So let’s try it out and run the module and see what happens there. It doesn’t create an error, but as you would see if we also print the captains dictionary down there,

01:23 then our captains dictionary now looks super weird with the spaceship names and the captains and the numbers and the spaceship names in there.

01:32 So I need to fix this error here and not use captains index, but of course winners index.

01:45 And now you can see that we have a winners dictionary with 1 Enterprise, 2 Defiant, and 3 Old Bessie, and our captains dictionary remains untouched.

01:55 That’s why I left the print() function call there in the end. But now that I know everything works as expected, I can remove this print() function call and I can also remove all those comments and blank lines so we have the for loop and the print() function.

02:13 Call to winners and only one comment left. Loop over the captains dictionary and congratulate them for their position in the space race.

02:24 Let’s do that next.

Become a Member to join the conversation.