MSNCodeSNIPPETS← msncode.dev
snippets/python

Virtual Environment Setup

Create and activate a Python virtual environment

pythonbashvenvsetup
BASH
python -m venv .venv && source .venv/bin/activate  # Windows: .venv\Scripts\activate

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