Skip to content

Commit de56684

Browse files
committed
add introduction
1 parent 24e7732 commit de56684

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

README.md

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
# Python for coding interviews
2+
List of several and useful `Python` data structures to know for coding interviews.
3+
4+
It is intended to show main data structures incorporated in the language
5+
and their useful functions. More advance `Python` feature will not be shown here.
6+
7+
Information described here, can be integrated with the following list:
8+
9+
| **Topic** | **Link** |
10+
|---|---|
11+
| Time complexity | https://wiki.python.org/moin/TimeComplexity |
12+
| Python collections | https://docs.python.org/3/library/collections.html |
213

314

415
## Primitive Types
16+
1. Booleans (`bool`).
517
1. Integers (`int`).
618
1. Floats (`float`).
719
1. Strings (`str`).
8-
1. Booleans (`bool`).
920

1021
```python
11-
>>> i, f, s, b = 12, 8.31, 'Hello, world!', True
22+
# Define variables
23+
>>> b, i, f, s = True, 12, 8.31, 'Hello, world!'
24+
>>> type(b) # <class 'bool'>
1225
>>> type(i) # <class 'int'> ~ Unbounded
1326
>>> type(f) # <class 'float'> ~ Bounded
1427
>>> type(s) # <class 'str'>
15-
>>> type(b) # <class 'bool'>
1628

29+
# Type Conversion
1730
>>> str(i)
1831
'12'
1932
>>> float(i)
@@ -22,29 +35,33 @@
2235
'True'
2336
>>> int('10')
2437
10
25-
>>> bool('a')
26-
True
27-
>>> bool(1)
28-
True
29-
>>> bool('')
30-
False
31-
>>> bool(0.0)
32-
False
33-
>>> bool(0)
34-
False
35-
36-
>>> min(i, 1)
37-
1
38-
>>> max(i, 1)
39-
12
40-
>>> max(i, f)
41-
12
38+
>>> int('10a') # ValueError: invalid literal for int() with base 10: '10a'
39+
40+
# Operations
41+
>>> 2 * 2
42+
4
43+
>>> 2 * 2.
44+
4.0
45+
>>> 4 / 2
46+
2.0
47+
>>> 4 // 2 # `//` is the integer division
48+
2
4249

43-
>>> pow(2, 3)
44-
8
45-
>>> 2 ** 3
50+
# `min` and `max`
51+
>>> min(4, 2)
52+
2
53+
>>> max(21, 29)
54+
29
55+
56+
# Some useful math functions
57+
>>> abs(-1.2)
58+
1.2
59+
>>> divmod(9, 4)
60+
(2, 1)
61+
>>> 2 ** 3 # Equivalent to `pow(2, 3)`
4662
8
4763

64+
# Math functions from the proper package
4865
>>> import math
4966
>>> math.ceil(7.2)
5067
8
@@ -53,15 +70,18 @@ False
5370
>>> math.sqrt(4)
5471
2.0
5572

56-
>>> float('inf') # Pseudo max-int
57-
inf
73+
# Pseudo lower and upper bounds
5874
>>> float('-inf') # Pseudo min-int
5975
-inf
76+
>>> float('inf') # Pseudo max-int
77+
inf
6078
```
6179

6280

6381
### Bit manipulation
82+
```python
6483
TODO
84+
```
6585

6686

6787
## Tuples
@@ -88,8 +108,6 @@ TODO
88108
1
89109
```
90110

91-
92-
93111
## Lists
94112
More info about time complexity for lists can be found [here][python-time-complexity].
95113
```python
@@ -183,9 +201,6 @@ True
183201
'a'
184202
```
185203

186-
187-
188-
189204
## Stacks
190205
```python
191206
>>> stack = []
@@ -498,8 +513,3 @@ first 1
498513
second 2
499514
third 3
500515
```
501-
502-
503-
504-
[python-time-complexity]: https://wiki.python.org/moin/TimeComplexity
505-
[python-collections]: https://docs.python.org/3/library/collections.html

0 commit comments

Comments
 (0)