Python Examples

Browse Python examples

pythonSnippet

ord And chr Map Code Points

ord returns the code point behind a character and chr inverts it, so char-level text math works on Unicode strings that iterate one code point at a time.

pythonSnippet

Flat Rows To Nested Tree

Index rows by id, attach each child under its parent reference, and collect roots separately, turning flat rows into a nested tree in one pass.

pythonSnippet

Palindrome Check Two Pointers

Walk two pointers inward from both ends, skipping non-alphanumeric characters and comparing lowercased letters, so punctuation-laden phrases still verify.

pythonSnippet

Prefix Sum Range Queries

Build one prefix array up front, then answer any range sum query with a single subtraction instead of re-summing the slice every time.

pythonSnippet

Two Heap Running Median

Split a value stream across two heapq heaps so every insert rebalances the halves and yields the exact running median without re-sorting.