MSNCodeSNIPPETS← msncode.dev
snippets/python

Sort List of Dicts by Key

Sort a list of dictionaries by a specific key

pythonpythonsortdict
PYTHON
sorted(items, key=lambda x: x['name'])

More python snippets

Dictionary with Default Value

Auto-create keys with a default value

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