Create a Dictionary (Solution)
00:00 Here on my screen, you can see the IDLE shell, which I’ll probably use for most of the exercises. Once we need to write a bit more code, I’ll probably change into the IDLE editor, but if you are not so comfortable with IDLE, it’s also perfectly fine to do this either in the editor of your choice or another Python REPL.
00:21
Okay, let’s warm up by creating an empty dictionary. I can basically think of two solutions for this one. So let’s do both because it’s a short one. The first one is you declare a variable named captains
, and then you use curly braces, so an opening and a closing curly brace,
00:48
and that creates an empty dictionary. The second solution would be you again, create a variable name captains
, and then you use the dict()
function, which again
01:02 creates an empty dictionary. Basically, you can use either or. I like the first one a bit better because it’s more literal, but the second variant can come in handy when you want to pass an iterable in while creating the dictionary, which might help us later in this course.
01:20 But for now, we solved this exercise, so let’s move on to the next one.
Become a Member to join the conversation.