Skip to content

Commit 3adda6a

Browse files
maxim-belkinRui Benfeitaswrightaprilm
authored
01-short-introduction-to-Python.md: Change dictionary keys from integers to strings (#445)
Fixes #360. Co-authored-by: Rui Benfeitas <[email protected]> Co-authored-by: April Wright <[email protected]>
1 parent 4901cf0 commit 3adda6a

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

_episodes/01-short-introduction-to-Python.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,20 @@ a_list = [1, 2, 3]
368368
A **dictionary** is a container that holds pairs of objects - keys and values.
369369

370370
~~~
371-
translation = {'one': 1, 'two': 2}
371+
translation = {'one': 'first', 'two': 'second'}
372372
translation['one']
373373
~~~
374374
{: .language-python}
375375
~~~
376-
1
376+
'first'
377377
~~~
378378
{: .output}
379379

380380
Dictionaries work a lot like lists - except that you index them with *keys*.
381-
You can think about a key as a name or unique identifier for the value it corresponds to.
381+
You can think about a key as a name or unique identifier for the value it corresponds to.
382382
~~~
383-
rev = {1: 'one', 2: 'two'}
384-
rev[1]
383+
rev = {'first': 'one', 'second': 'two'}
384+
rev['first']
385385
~~~
386386
{: .language-python}
387387
~~~
@@ -392,13 +392,13 @@ rev[1]
392392
To add an item to the dictionary we assign a value to a new key:
393393

394394
~~~
395-
rev = {1: 'one', 2: 'two'}
396-
rev[3] = 'three'
395+
rev = {'first': 'one', 'second': 'two'}
396+
rev['third'] = 'three'
397397
rev
398398
~~~
399399
{: .language-python}
400400
~~~
401-
{1: 'one', 2: 'two', 3: 'three'}
401+
{'first': 'one', 'second': 'two', 'third': 'three'}
402402
~~~
403403
{: .output}
404404

@@ -412,9 +412,9 @@ for key, value in rev.items():
412412
{: .language-python}
413413

414414
~~~
415-
1 -> one
416-
2 -> two
417-
3 -> three
415+
'first' -> one
416+
'second' -> two
417+
'third' -> three
418418
~~~
419419
{: .output}
420420

@@ -426,17 +426,17 @@ for key in rev.keys():
426426
~~~
427427
{: .language-python}
428428
~~~
429-
1 -> one
430-
2 -> two
431-
3 -> three
429+
'first' -> one
430+
'second' -> two
431+
'third' -> three
432432
~~~
433433
{: .output}
434434

435435
> ## Changing dictionaries
436436
>
437437
> 1. First, print the value of the `rev` dictionary to the screen.
438-
> 2. Reassign the value that corresponds to the key `2` so that it no longer
439-
> reads "two" but instead "apple-sauce".
438+
> 2. Reassign the value that corresponds to the key `second` so that it no longer
439+
> reads "two" but instead `2`.
440440
> 3. Print the value of `rev` to the screen again to see if the value has changed.
441441
{: .challenge}
442442

0 commit comments

Comments
 (0)