Skip to content

Commit 104cacc

Browse files
yradmaxim-belkin
authored andcommitted
01-short-introduction-to-Python.md: update section on dictionaries (#433)
1 parent 11010eb commit 104cacc

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ keypoints:
1414
- "Python is an interpreted language which can be used interactively (executing one command at a time) or in scripting mode (executing a series of commands saved in file)."
1515
- "One can assign a value to a variable in Python. Those variables can be of several types, such as string, integer, floating point and complex numbers."
1616
- "Lists and tuples are similar in that they are ordered lists of elements; they differ in that a tuple is immutable (cannot be changed)."
17-
- "Dictionaries are unordered data structures that provide mappings between keys and values."
17+
- "Dictionaries are data structures that provide mappings between keys and values."
1818
---
1919

2020
## Interpreter
@@ -378,10 +378,7 @@ translation['one']
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 for or a unique identifier for a set of values
382-
in the dictionary. Keys can only have particular types - they have to be
383-
"hashable". Strings and numeric types are acceptable, but lists aren't.
384-
381+
You can think about a key as a name or unique identifier for the value it corresponds to.
385382
~~~
386383
rev = {1: 'one', 2: 'two'}
387384
rev[1]
@@ -392,20 +389,6 @@ rev[1]
392389
~~~
393390
{: .output}
394391

395-
~~~
396-
bad = {[1, 2, 3]: 3}
397-
~~~
398-
{: .language-python}
399-
~~~
400-
Traceback (most recent call last):
401-
File "<stdin>", line 1, in <module>
402-
TypeError: unhashable type: 'list'
403-
~~~
404-
{: .output}
405-
406-
In Python, a "Traceback" is an multi-line error block printed out for the
407-
user.
408-
409392
To add an item to the dictionary we assign a value to a new key:
410393

411394
~~~

0 commit comments

Comments
 (0)