https://jeffknupp.com/blog/2018/10/11/write-better-python-functions/
What differentiates a "good" Python function from a crappy one? You'd be surprised at how many definitions of "good" one can use. For our purposes, I'll consider a Python function "good" if it can tick off most of the items on this checklist (some are not always possible):
Is sensibly named
Has a single responsibility
Includes a docstring
Returns a value
Is not longer than 50 lines
Is idempotent and, if possible, pure
For many of you, this list may seem overly draconian. I promise you, though, if your functions follow these rules, your code will be so beautiful it will make unicorns weep. Below, I'll devote a section to each of the items, then wrap things up with how they work in harmony to create "good" functions.