11# Python for coding interviews
2+
23List of several and useful ` Python ` data structures to know for coding interviews.
34
45It is intended to show main data structures incorporated in the language
@@ -8,11 +9,11 @@ Information described here, can be integrated with the following list:
89
910| ** Topic** | ** Link** |
1011| ---| ---|
11- | Time complexity | https://wiki.python.org/moin/TimeComplexity |
12- | Python collections | https://docs.python.org/3/library/collections.html |
13-
12+ | Time complexity | < https://wiki.python.org/moin/TimeComplexity > |
13+ | Python collections | < https://docs.python.org/3/library/collections.html > |
1414
1515## Primitive Types
16+
16171 . Booleans (` bool ` ).
17181 . Integers (` int ` ).
18191 . Floats (` float ` ).
@@ -77,14 +78,14 @@ Information described here, can be integrated with the following list:
7778inf
7879```
7980
80-
8181### Bit manipulation
82+
8283``` python
8384TODO
8485```
8586
86-
8787## Tuples
88+
8889``` python
8990>> > t = (1 , 2 , ' str' )
9091>> > type (t)
109110```
110111
111112## Lists
113+
112114More info about time complexity for lists can be found [ here] [ python-time-complexity ] .
115+
113116``` python
114117>> > l = [1 , 2 , ' a' ]
115118>> > type (l) # <class 'list'>
176179True
177180```
178181
179-
180182## Strings
183+
181184``` python
182185>> > s = ' Hello, world!'
183186>> > type (s) # <class 'str'>
202205```
203206
204207## Stacks
208+
205209``` python
206210>> > stack = []
207211
232236>> > stack[- 1 ] # `IndexError: pop from empty list`
233237```
234238
235-
236239## Queues
240+
237241``` python
238242>> > from collections import deque
239243
271275>> > queue[0 ] # `IndexError: pop from an empty deque`
272276```
273277
274-
275278## Sets
279+
276280``` python
277281>> > s = set ()
278282>> > s.add(1 )
325329{2 }
326330```
327331
328-
329332## Hash Tables
333+
330334``` python
331335>> > d = {' a' : ' hello, world' , b: 11 }
332336>> > type (d)
@@ -364,18 +368,18 @@ False
364368' a new element'
365369```
366370
367-
368371## Heaps
372+
369373The following commands show how to work with a min heap.
370374Currently, Python does not have public methods for the max heap.
371375You can overcome this problem by applying one of the following strategies:
376+
3723771 . Invert the value of each number. So, for example, if you want to add
373378 1, 2 and 3 in the min heap, you can ` heappush ` -3, -2 and -1.
374379 When you ` heappop ` you invert the number again to get the proper value.
375380 This solution clearly works if your domain is composed by numbers &ge ; 0.
3763811 . [ Invert your object comparison] ( https://stackoverflow.com/a/40455775 ) .
377382
378-
379383``` python
380384>> > import heapq
381385
@@ -406,17 +410,13 @@ You can overcome this problem by applying one of the following strategies:
406410>> > heapq.heappop(min_heap) # `IndexError: index out of range`
407411```
408412
409-
410413## Searching
414+
411415``` python
412416```
413417
418+ ### collections.namedtuple
414419
415- ## collections
416- More information about container datatypes can be found
417- in [ the official documentation] [ python-collections ] .
418-
419- ### namedtuple
420420``` python
421421>> > from collections import namedtuple
422422
448448True
449449```
450450
451+ ### collections.defaultdict
451452
452- ### defaultdict
453453``` python
454454>> > from collections import defaultdict
455455
@@ -471,8 +471,8 @@ defaultdict(<class 'int'>, {'x': 3, 'y': 10})
471471defaultdict(< class ' list' > , {' x' : [1 , 2 ]})
472472```
473473
474+ ### collections.Counter
474475
475- ### Counter
476476``` python
477477>> > from collections import Counter
478478
4934930
494494```
495495
496+ ### collections.OrderedDict
496497
497- ### OrderedDict
498498``` python
499499>> > from collections import OrderedDict
500500
0 commit comments