MSNCodeSNIPPETS← msncode.dev
snippets/python

Read File Line by Line

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

pythonpythonfileread
PYTHON
with open('file.txt') as f: for line in f: print(line.strip())

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

Sort List of Dicts by Key

Sort a list of dictionaries by a specific key