Skip to content

Commit df9b509

Browse files
danielquinnrichardwestenra
authored andcommitted
Fixed some bugs (#340)
During the meetup today we ran into these two errors in the tutorial: * It turns out that you can't use dictionaries as keys for other dictionaries. * I had a syntax error in one of the dictionaries
1 parent 9d32046 commit df9b509

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

python/lesson3/tutorial.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,25 @@ You can have *anything* in there:
214214
"a string": "hello, world!",
215215
"a list": ["This", "is my", "list"],
216216
"another dictionary!": {
217-
{
218-
"Arya": "+4407485376242",
219-
"Breanne": "+3206785246863",
220-
"Cersei": "+14357535455",
221-
"Davos": "+244562726258"
222-
}
217+
"Arya": "+4407485376242",
218+
"Breanne": "+3206785246863",
219+
"Cersei": "+14357535455",
220+
"Davos": "+244562726258"
223221
}
222+
}
224223

225-
Actually, you can have any type you like as a *key* as well, though this can
226-
sometimes lead to reduced readability, so use this with caution. For example,
227-
while this is valid Python, it's not exactly easy to understand:
224+
Actually, you can have all kinds of *keys*: tuples, even functions and classes
225+
can be used for keys, though this can sometimes lead to reduced readability,
226+
so use this with caution. For example, while this is valid Python, it's not
227+
exactly easy to understand:
228228

229229
my_unreadable_dictionary = {
230-
{"a number": 8}: {"a string": "hello, world!"}
230+
("this", "is", "a", "tuple!"): {"a string": "hello, world!"}
231231
}
232232

233+
You can't however use a list or a dictionary as a key, which is probably a
234+
good thing 'cause that'd be super confusing.
235+
233236
Your turn: try creating a dictionary or two of your own. Try using different
234237
types as keys and values, and then try to access them using the standard
235238
`my_dictionary["my key"]` syntax.

0 commit comments

Comments
 (0)