Just Enough Python - keshavbaweja-git/guides GitHub Wiki
# Length of a string/tuple/list
len(a)
# String to list
aList = list(a)
# List to String
a = "".join(aList)
# String to Integer
aInt = int(a)
# Integer to String
a = str(aInt)
# Range - (0:n]
range(n)
# Add an element b to a list aList
aList.append(b)
# Add all elements of list bList to list aList
aList.extend(bList)
# Iterate items in a dictionary
for k, v in aDict.items():
# Flatten an iterable
def flattenList(array):
res = []
for el in array:
if isinstance(el, (list, tuple)):
res.extend(flattenList(el))
continue
res.append(el)
return res
# Combinations of two iterables
import itertools
combos = itertools.combinations(a, b)
# Product of two iterables
import itertools
productList = list(itertools.product(a, b))
# Product of nested lists
a = [1,2], [3,4](/keshavbaweja-git/guides/wiki/1,2],-[3,4)
b = list(itertools.product(*a))
b
[(1, 3), (1, 4), (2, 3), (2, 4)]
# venv
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install --upgrade wheel
pip install --upgrade build
python -m build .