You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/01-short-introduction-to-Python.md
+2-19Lines changed: 2 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ keypoints:
14
14
- "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)."
15
15
- "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."
16
16
- "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."
18
18
---
19
19
20
20
## Interpreter
@@ -378,10 +378,7 @@ translation['one']
378
378
{: .output}
379
379
380
380
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.
385
382
~~~
386
383
rev = {1: 'one', 2: 'two'}
387
384
rev[1]
@@ -392,20 +389,6 @@ rev[1]
392
389
~~~
393
390
{: .output}
394
391
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
-
409
392
To add an item to the dictionary we assign a value to a new key:
0 commit comments