$ pip freeze > args | pip uninstall -y -r args | rm args
""" | |
Project structure: | |
demo_reader | |
src | |
demo_reader | |
compressed | |
__init__.py | |
bzipped.py | |
gzipped.py |
""" | |
Flatten a List | |
There is a list which contains integers or other nested lists which may contain yet | |
more lists and integers which then may contain more lists ... | |
You should put all of the integer values into one flat list. The order should be as it | |
was in the original list with string representation from left to right. | |
Your code should be shorter than 140 characters (with whitespaces). |
: create virtual environment | |
python -m venv ./venv | |
: create activate.bat file | |
echo .\venv\scripts\activate.bat > activate.bat | |
: activate virtual env | |
call activate.bat | |
: update pip |
file = "some_file_path.csv" | |
# Option #1 using readlines(). It will create list of lines | |
with open(file, "r") as reader: | |
lines = reader.readlines() | |
# Option #2. Read line by line and add to the list | |
with open(file, "r") as reader: | |
lines = [] | |
for line in reader: |
""" | |
An example of how to annotate cls return type class in inheritance using mypy | |
in order to escape error `AttributeError: type object 'A' has no attribute 'bazz'` | |
Here is what we done: | |
* The type variable TA is used to denote that return values might be an | |
instances of subclasses of A. | |
* Specify that A is an upper bound for TA. | |
Specifying bound means that TA will only be A or one of its subclasses. | |
This is needed to properly restrict the types that are allowed. |
""" | |
Creates 2D matrix | |
""" | |
def matrix(rows, cols, start=0): | |
return [[c + start + r * cols for c in range(cols)] for r in range(rows)] | |
assert matrix(2, 3, 1) == [[1, 2, 3], [4, 5, 6]] |
""" | |
List allocation with teh same value using different techniques | |
The winner is [value] * times by between 15-25 times | |
""" | |
from timeit import timeit | |
from itertools import repeat | |