MSNCodeSNIPPETS← msncode.dev
snippets/python

Dictionary with Default Value

Auto-create keys with a default value

pythonpythondictdefault
PYTHON
from collections import defaultdict
counts = defaultdict(int)

More python snippets

Enumerate with Index

Loop through a list with both index and value

Filter List with Comprehension

Filter a list using a conditional list comprehension

Read File Line by Line

Read a file line by line without loading it all into memory

Sort List of Dicts by Key

Sort a list of dictionaries by a specific key