Snippets
Reusable code snippets for Python, JavaScript, HTML, CSS, SQL, and more. Copy and use in your projects.
List Comprehension One-Liner
Build a new list from an iterable in a single readable line — faster and more Pythonic than a for-loop.
squares = [x * x for x in range(10) if x % 2 == 0]
# [0, 4, 16, 36, 64]listcomprehensionpythonic 76
Open pageLambda Functions
Anonymous one-line functions perfect for short callbacks like sorting keys or quick transforms.
nums = [5, 2, 8, 1, 9]
nums.sort(key=lambda n: -n)
# [9, 8, 5, 2, 1]
# also useful with map/filter
doubled = list(map(lambda n: n * 2, nums))lambdafunctionalsort 74
Open pageF-String Formatting
Format strings inline with expressions, numbers, and dates — the cleanest way to build strings in Python 3.6+.
name = "Aarav"
score = 95.5
print(f"{name} scored {score:.1f}%")
# Aarav scored 95.5%stringformattingf-string 65
Open page