@ -66,8 +66,8 @@ Range
range(to_exclusive)
range(to_exclusive)
range(from_inclusive, to_exclusive)
range(from_inclusive, to_exclusive)
range(from_inclusive, to_exclusive, step_size)
range(from_inclusive, to_exclusive, step_size)
range(from_inclusive, to_exclusive, -step_size)
```
```
* Negative `step_size` can be used for backward range.
Enumerate
Enumerate
---------
---------
@ -89,20 +89,27 @@ TestResults(filed=1, attempted=2)
Iterator
Iterator
--------
--------
#### Skips first element:
```python
next(< iter > )
for element in < iter > :
...
```
#### Reads input until it reaches an empty line:
#### Reads input until it reaches an empty line:
```python
```python
for line in iter(input, ''):
for line in iter(input, ''):
...
...
```
```
* Use `partial` from functools if function needs arguments.
#### Skips first element :
#### Same, but prints a message every time :
```python
```python
next(< iter > )
for element in < iter > :
from functools import partial
for line in iter(partial(input, 'Please enter value'), '') :
...
...
```
```
Generator
Generator
---------
---------
```python
```python
@ -207,18 +214,18 @@ now.strftime('%Y%m%d%H%M%S') # 20180315002834
Arguments
Arguments
---------
---------
#### "*" is the splat operator, that takes a list as input, and expands it into actual positional arguments in the function call:
```python
```python
args = (1, 2)
args = (1, 2)
kwargs = {'x': 3, 'y': 4, 'z': 5}
kwargs = {'x': 3, 'y': 4, 'z': 5}
func(*args, **kwargs)
func(*args, **kwargs)
```
```
#### Is the same as:
#### Is the same as:
```python
```python
func(1, 2, x=3, y=4, z=5)
func(1, 2, x=3, y=4, z=5)
```
```
* "*" is the splat operator, that takes a list as input, and expands it into actual positional arguments in the function call.
Inline
Inline
------
------
@ -464,7 +471,7 @@ lock.release()
Itertools
Itertools
---------
---------
Every function returns a generator and can accept any collection. If you want to
#### Every function returns a generator and can accept any collection. If you want to
print an output of generator, as in examples, you need to pass it to _list()_
print an output of generator, as in examples, you need to pass it to _list()_
function.
function.
@ -534,7 +541,7 @@ islice([1, 2, 3], 1, None)
```
```
### Ifilter, imap and izip
### Ifilter, imap and izip
* Filter, map and zip functions that return generators instead of iterators.
* #### Filter, map and zip functions that return generators instead of iterators.
Introspection and Metaprograming
Introspection and Metaprograming
@ -579,7 +586,7 @@ False
```
```
### Type
### Type
Type is the root class. If only passed the object it returns it's type.
EEEE Type is the root class. If only passed the object it returns it's type.
Otherwise it creates a new class (and not the instance!).
Otherwise it creates a new class (and not the instance!).
```python
```python
type(class_name, parents< tuple > , attributes< dict > )
type(class_name, parents< tuple > , attributes< dict > )
@ -606,7 +613,7 @@ class MyMetaClass(type):
```
```
### Metaclass Attr
### Metaclass Attr
When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined, and eventually comes to type.
#### When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined, and eventually comes to type.
```python
```python
class BlaBla:
class BlaBla:
__metaclass__ = Bla
__metaclass__ = Bla