4 built-in containers: list, tuple, set and dict...
4 built-in containers: list, tuple, set and dict.
For more containers: see [collections](https://docs.python.org/3/library/collections.html)...
%% Cell type:markdown id: tags:
...
...
@@ -39,11 +39,11 @@
%% Cell type:markdown id: tags:
### list: mutable sequence
The builtin function `dir` returns a list of name of the attributes. For a list, these attributes are python system attributes (with double-underscores) and 11 public methods:
The built-in function `dir` returns a list of name of the attributes. For a list, these attributes are python system attributes (with double-underscores) and 11 public methods:
%% Cell type:code id: tags:
``` python
...
...
@@ -169,12 +169,12 @@
t0=()
t1=tuple()
assertt0==t1
# not empty tuple
t2=(1,2,'a')# with the parenthesis
t2=1,2,'a'# it also works without parenthesis
t2=(1,2,'a')# with the parentheses
t2=1,2,'a'# it also works without parentheses
t3=tuple(l3)# from a list
```
%% Cell type:code id: tags:
...
...
@@ -314,17 +314,17 @@
12
%% Cell type:markdown id: tags:
## Complity :
## Complexity :
- line 1: n insertions --> O(n)
- line 2: n insertions --> O(n)
- line 2: n insertions --> O(n)
- line 3: one traversal O(n), with one lookup at each time (O(1) -> O(n)
-> Complixity of the whole algorithm : O(n)
-> Complexity of the whole algorithm : O(n)
# Complexity of the "sum" solution :
- One traversal for the computation of the sum O(n) with sum at each step O(1) -> O(n)
%% Cell type:markdown id: tags:
...
...
@@ -393,11 +393,13 @@
'value1'
%% Cell type:markdown id: tags:
But warning, `dict` are not ordered (since they are based on a hashtable)!
**Warning:** In general, `dict` are not ordered (since they are based on a hashtable)!
However, since Python 3.6, the implementation changed so that `dict` now keep the order of insertion of keys.