Thoughts, notes, and explanations on Python, Data Structures, Algorithms, Machine Learning, and learning how to learn effectively.
This section will grow over time with structured posts and practical insights.
Thoughts, notes, and explanations on Python, Data Structures, Algorithms, Machine Learning, and learning how to learn effectively.
This section will grow over time with structured posts and practical insights.

Python Functions Masterclass A Complete Guide from Basics to Advanced Concepts Who is this for? You know Python basics and have some experience with loops and collections. This guide covers every important concept around functions in Python – from defining your first function all the way through decorators and closures. Every concept is explained with a simple example first. Table of Contents What is a Function and Why Use One? Defining and Calling Functions Parameters and Arguments Default Parameters *args – Variable Positional Arguments **kwargs – Variable Keyword Arguments Combining All Argument Types Return Values Scope and the LEGB Rule global and nonlocal Keywords Docstrings and Function Annotations Lambda Functions Higher Order Functions map(), filter(), and reduce() Closures Decorators Decorators with Arguments Chaining Multiple Decorators Recursion Generator Functions and yield Practice Questions Solutions What We Covered and What is Next 1. What is a Function and Why Use One? Imagine you need to calculate GST on product prices in three different parts of your program. Without a function, you write the same calculation three times. If the GST rate changes, you update it in three places – and likely miss one. ...

Lesson 3 - Aggregations & Grouping Theory + Practice | CricketDB + ShopDB Before You Start This lesson uses both databases you have already built: CricketDB - players, matches, performances (Lesson 2.1) ShopDB - customers, products, orders, order_items (Lesson 2.2) Run the setup_check.sql from this lesson folder to confirm both are ready. Each section tells you which database to connect to in pgAdmin. What you will learn in this lesson: ...

Python Higher-Order Functions & Decorators A Complete Reference Guide Table of Contents The Big Picture Functions as First-Class Objects Higher-Order Functions Closures - The Foundation of Decorators Decorators - Core Concept The @ Syntax Preserving Metadata with functools.wraps Decorators with Arguments Class-Based Decorators Stacking Multiple Decorators Built-in Decorators Practical Decorator Patterns Common Mistakes to Avoid Practice Questions & Answers Quick Reference Cheat Sheet The Big Picture ┌─────────────────────────────────────────────────────────────────────┐ │ THE DECORATOR MENTAL MODEL │ │ │ │ A decorator is a function that WRAPS another function │ │ to add behaviour before, after, or around it. │ │ │ │ Original Function │ │ ┌────────────────┐ │ │ │ do_thing() │ │ │ └────────────────┘ │ │ │ decorator applied │ │ ▼ │ │ ┌────────────────────────────────────┐ │ │ │ wrapper() │ │ │ │ ┌──────────────────────────────┐ │ │ │ │ │ before logic (logging etc) │ │ │ │ │ ├──────────────────────────────┤ │ │ │ │ │ do_thing() ← called │ │ │ │ │ ├──────────────────────────────┤ │ │ │ │ │ after logic (timing etc) │ │ │ │ │ └──────────────────────────────┘ │ │ │ └────────────────────────────────────┘ │ │ │ │ @decorator is sugar for: func = decorator(func) │ └─────────────────────────────────────────────────────────────────────┘ Core Idea: A decorator is just a callable that takes a function and returns a new callable. Everything else - the @ syntax, functools.wraps, parameterised decorators - builds on top of this single idea. ...

Lesson 2.7 - Indexes, Constraints & Schema Design Theory + Practice | All Three Databases Before You Start This lesson uses all three databases. Each section tells you which one to connect to. Quick check - run this in each database before starting: -- In cricketdb: SELECT COUNT(*) FROM performances; -- expect 30 -- In shopdb: SELECT COUNT(*) FROM order_items; -- expect 30+ -- In streamdb: SELECT COUNT(*) FROM watch_history; -- expect 50 What you will learn: ...

SQL Lecture 01 - Introduction to SQL & Databases PostgreSQL | Beginner Reference Sheet | Use this during class 🐘 Table of Contents What is a Database? Types of Databases What is SQL? How SQL Commands Are Grouped Creating a Table - Full Breakdown Data Types in PostgreSQL Constraints - Rules for Your Data Primary Key & Foreign Key Common SQL Commands with Examples What Happens When You Violate a Constraint? Practice Table & 10 Beginner Questions 1. What is a Database? A database is an organised collection of data stored so it can be easily accessed, managed, and updated. ...

Python Iterables, Iterators & Generators A Complete Lesson Plan & Reference Guide Table of Contents The Big Picture Iterables Iterators The Iterator Protocol Building Custom Iterators Generators Generator Expressions Advanced Generator Features Common Pitfalls & Things to Keep in Mind Real-Life Applications Practice Questions & Answers Quick Reference Cheat Sheet The Big Picture Before diving in, here’s the conceptual map you need to hold in your head: ┌──────────────────────────────────────────────────┐ │ ITERABLE │ │ Any object you can loop over with a for loop │ │ Examples: list, tuple, str, dict, set, file │ │ │ │ Has __iter__() → returns an Iterator │ └──────────────────────┬───────────────────────────┘ │ __iter__() called ▼ ┌──────────────────────────────────────────────────┐ │ ITERATOR │ │ An object that knows where it is in a sequence │ │ and can produce the next value on demand │ │ │ │ Has __iter__() → returns self │ │ Has __next__() → returns next value or raises │ │ StopIteration │ └──────────────────────┬───────────────────────────┘ │ special case of ▼ ┌──────────────────────────────────────────────────┐ │ GENERATOR │ │ A convenient way to create iterators using │ │ the `yield` keyword - Python auto-builds the │ │ iterator protocol for you │ └──────────────────────────────────────────────────┘ Key Insight: Every iterator is an iterable, but not every iterable is an iterator. A list is an iterable but NOT an iterator. iter(list) gives you an iterator. ...

Python’s itertools - The Missing Manual A deep dive into one of Python’s most underused standard library modules Wait, Why Should I Care About Another Module? You’ve written Python for a while. You know how to use for loops, list comprehensions, zip, and enumerate. Things work. So when someone says “hey, you should learn itertools”, it’s easy to nod politely and move on. Here’s what changes your mind. Imagine you’re asked to generate all possible batting orders for 4 players chosen from a squad of 11. Or you need to group a massive log file by date without loading it all into memory. Or you want to pair up every possible combination of feature columns for a machine learning experiment. ...

Lesson 4 - JOINs & Relationships Theory + Practice | ShopDB Before You Start This lesson uses ShopDB exclusively. Connect to shopdb in pgAdmin before running any query. Run this to confirm your data is ready: SELECT 'customers' AS t, COUNT(*) FROM customers UNION ALL SELECT 'products', COUNT(*) FROM products UNION ALL SELECT 'orders', COUNT(*) FROM orders UNION ALL SELECT 'order_items',COUNT(*) FROM order_items; -- Expected: 20, 25, 15, 30 What you will learn: ...

Lesson 5 - Subqueries & CTEs Theory + Practice | StreamDB - Indian Streaming Platform Before You Start This lesson introduces StreamDB - a Hotstar-style streaming platform. Run setup.sql to create and populate StreamDB Verify you see 6 tables with the correct row counts Connect to streamdb in pgAdmin before running any query The StreamDB schema: users shows genres ┌────┬───────┬──────┐ ┌────┬────────┬──────────┐ ┌────┬──────────┐ │ id │ name │ plan │ │ id │ title │is_premium│ │ id │ name │ └────┴───────┴──────┘ └────┴────────┴──────────┘ └────┴──────────┘ │ │ │ │ │ show_genres │ │ │ ┌──────────────┘ ┌────────────┘ │ │ show_id | genre_id │ │ └──────────────────────────┘ (many-to-many) │ subscriptions watch_history ┌────┬─────────┬──────────────┐ ┌────┬─────────┬─────────┬─────────┐ │ id │ user_id │ plan │ │ id │ user_id │ show_id │ minutes │ │ │ │ started_on │ │ │ │ watched │ watched │ │ │ │ expires_on │ └────┴─────────┴─────────┴─────────┘ └────┴─────────┴──────────────┘ What you will learn: ...