MSNCodeSNIPPETS← msncode.dev
snippets/python

Enumerate with Index

Loop through a list with both index and value

pythonpythonenumerateloop
PYTHON
for i, val in enumerate(items):
    print(i, val)

More python snippets

Dictionary with Default Value

Auto-create keys with a default 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