File tree Expand file tree Collapse file tree 1 file changed +45
-2
lines changed
Expand file tree Collapse file tree 1 file changed +45
-2
lines changed Original file line number Diff line number Diff line change 6565
6666
6767## Arrays
68- TODO
68+ More info about time complexity for lists can be found [ here] [ python-time-complexity ] .
69+ ``` python
70+ >> > l = [1 , 2 , ' a' ]
71+ >> > type (l) # <class 'list'>
72+ >> > len (l)
73+ 3
74+ >> > l[0 ] # First element of the list
75+ 1
76+ >> > l[- 1 ] # Last element of the list (equivalent to `l[len(l) - 1]`)
77+ ' a'
78+
79+ >> > l.append(' b' ) # `O(1)`
80+ >> > l.pop() # `O(1)` just for the last element
81+ ' b'
82+ >> > l.pop(0 ) # `O(n)` since list must be shifted
83+ 1
84+ >> > l
85+ [2 , ' a' ]
86+ >> > l.remove(' a' ) # `O(n)`
87+ >> > l.remove(' b' ) # `ValueError: list.remove(x): x not in list`
88+ >> > l
89+ [2 ]
90+ >> > l.index(2 )
91+ 0
92+ >> > l.index(12 ) # ValueError: 12 is not in list
93+
94+ >> > l = [0 ] * 5
95+ >> > l
96+ [0 , 0 , 0 , 0 , 0 ]
97+ >> > len (l)
98+ 5
99+
100+ >> > rows, cols = 2 , 3
101+ >> > m = [[0 ] * cols for _ in range (rows)]
102+ >> > len (m) == rows
103+ True
104+ >> > all (len (m[k]) == cols for k in range (rows))
105+ True
106+ ```
69107
70108
71109## Strings
72- TODO
110+ - ord
111+ - chr
73112
74113
75114## Stacks
171210
172211
173212### OrderedDict
213+
214+
215+
216+ [ python-time-complexity ] : https://wiki.python.org/moin/TimeComplexity
You can’t perform that action at this time.
0 commit comments