Python Cheat Sheet
Useful Information about the Python programming language.
Pyenv
Iterator vs. Iterable
- iterable
- An object capable of returning its members one at a time.
- Provides an
__iter__()method.
- iterator
- An object representing a stream of data.
- Provides
__iter__()and__next__()methods. collections.abc.Iteratorinherits fromcollections.abc.Iterable.
Count the number of items in an iterable
from collections import deque
from itertools import count
def len_iter(iterable):
deque(maxlen=0).extend(zip(iterable, ctr := count()))
return next(ctr)
Source: ShadowRanger on StackOverflow (CC BY-SA 4.0)
Minimal pyproject.toml
Static version
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "project-name"
version = "0.1.0"
Dynamic version
[build-system]
requires = ["setuptools", "setuptools-scm[simple]"]
build-backend = "setuptools.build_meta"
[project]
name = "project-name"
dynamic = ["version"]
Sources
Minimal .flake8 config for Black
[flake8]
max-line-length = 88
extend-ignore = E203,E701
Source: Using Black with other tools