5th October 2021
Coding⚑
Python⚑
Python Snippets⚑
-
New: Check if a dictionary is a subset of another.
If you have two dictionaries
big = {'a': 1, 'b': 2, 'c':3}
andsmall = {'c': 3, 'a': 1}
, and want to check whethersmall
is a subset ofbig
, use the next snippet:>>> small.items() <= big.items() True
-
Correction: Group or sort a list of dictionaries or objects by a specific key.
Improve previous method with the concepts learned from the official docs
Particularly improve the sorting by multiple keys with the next function:
>>> def multisort(xs, specs): for key, reverse in reversed(specs): xs.sort(key=attrgetter(key), reverse=reverse) return xs >>> multisort(list(student_objects), (('grade', True), ('age', False))) [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
DevOps⚑
Continuous Integration⚑
Flakehell⚑
-
New: Troubleshoot the 'Namespace' object has no attribute 'extended_default_ignore' error.
Add to your
pyproject.toml
:[tool.flakeheaven] extended_default_ignore=[]