Possessing prodigious potential for producing pragmatic and proficient Python programs.
PunyPython is a Python-only educational reference repository. Every file is a runnable, heavily-commented script you can read, copy, paste, and experiment with.
| What | Details |
|---|---|
| π Primary section | LearnXinY/ β structured transcription of the canonical Learn X in Y Minutes β Python guide (Β© its contributors, CC BY-SA 3.0), each topic expanded with up to two additional original examples per concept |
| π€ Co-authored with | Claude (Anthropic), original supplemental examples also released under CC BY-SA 3.0 |
| βοΈ Algorithm folders | Arrays/, Lists/, Textual/, Mathmatical/ β multiple approaches to common problems, side-by-side for trade-off comparison |
| π License | Always Creative Commons. No proprietary content will ever be added. |
Note
The LearnXinY/ section is a structured transcription of the canonical
Learn X in Y Minutes β Python guide
(Β© its contributors, Creative Commons Attribution-ShareAlike 3.0 Unported).
Each topic is expanded with up to two additional original examples per concept,
co-authored with Claude (Anthropic), also released under CC BY-SA 3.0.
PunyPython/
β
βββ LearnXinY/ β Core language reference (learnxinyminutes transcription)
β βββ Primitives/
β β βββ numbers.py β integers, floats, arithmetic, operator precedence
β β βββ strings.py β creation, slicing, methods, f-strings, translate
β β βββ booleans_and_none.py β bool ops, comparisons, short-circuit, truthiness
β β
β βββ Variables/
β β βββ assignment.py β basic assignment, unpacking, swap, augmented, annotations
β β
β βββ Collections/
β β βββ lists.py β creation, indexing, slicing, mutation, methods
β β βββ tuples.py β immutability, unpacking, namedtuple, memory
β β βββ dictionaries.py β access, views, mutation, merge, Counter, defaultdict
β β βββ sets.py β operations, algebra, frozenset, deduplication
β β
β βββ ControlFlow/
β β βββ conditionals.py β if/elif/else, ternary, match/case, guard clauses
β β βββ loops.py β for, while, range, enumerate, zip, break/continue/else
β β βββ exceptions.py β try/except/else/finally, raise, custom exceptions, with
β β βββ comprehensions.py β list, set, dict comprehensions; generator expressions
β β
β βββ Functions/
β β βββ basics.py β def, return, scope, first-class, map/filter, lru_cache
β β βββ args_and_kwargs.py β *args, **kwargs, keyword-only, positional-only, unpacking
β β βββ closures_and_lambdas.py β closures, nonlocal, lambda, operator module
β β βββ decorators.py β @decorator, @wraps, arguments, stacking, class decorators
β β βββ generators.py β yield, generator expressions, yield from, send, pipelines
β β
β βββ Modules/
β β βββ imports.py β import, from/import, aliases, stdlib highlights, __name__
β β
β βββ Classes/
β βββ basics.py β class, __init__, instance attrs, __str__/__repr__, dataclass
β βββ properties_and_statics.py β @property, @classmethod, @staticmethod, cached_property
β βββ inheritance.py β single, multiple inheritance, super(), MRO, ABC, mixins
β βββ magic_methods.py β arithmetic, comparison, container, context manager, __call__
β
βββ Arrays/
β βββ rotate/ β 5 approaches to array rotation
β βββ sum_of_array/ β 5 approaches to summing an array
β βββ largest_element/ β 6 approaches to finding the largest element
β
βββ Lists/
β βββ swap_first_last/ β 4 approaches to swapping list ends
β
βββ Textual/
β βββ hello_world.py
β βββ ascii_value_of_char.py β print ASCII value of every character in user input
β βββ remove_nth_char.py β remove the character at index n (0-based) from a string
β
βββ Mathmatical/
β βββ Armstrong_number_check.py
β βββ factorial/ β 4 approaches (one requires numpy: pip install numpy)
β βββ maximum_of_2_numbers/ β 6 approaches
β βββ add_2_numbers/ β 6 approaches
β
βββ venv_manager.py β CLI tool for managing Python virtual environments
(Unix-first; Windows-compatible with caveats β see script header)
graph TD
ROOT["π PunyPython"]
ROOT --> LXY["π LearnXinY/\nCore language reference"]
ROOT --> ARR["π’ Arrays/\n5β6 approaches each"]
ROOT --> LST["π Lists/\n4 approaches"]
ROOT --> TXT["π€ Textual/\n3 scripts"]
ROOT --> MTH["β Mathmatical/\n4β6 approaches each"]
ROOT --> VNV["βοΈ venv_manager.py\nCLI venv tool"]
LXY --> PRI["Primitives\nnumbers Β· strings Β· booleans"]
LXY --> VAR["Variables\nassignment"]
LXY --> COL["Collections\nlists Β· tuples Β· dicts Β· sets"]
LXY --> CFW["ControlFlow\nconditionals Β· loops Β· exceptions Β· comprehensions"]
LXY --> FUN["Functions\nbasics Β· args Β· closures Β· decorators Β· generators"]
LXY --> MOD["Modules\nimports"]
LXY --> CLS["Classes\nbasics Β· properties Β· inheritance Β· magic_methods"]
ARR --> AR1["rotate/ β 5 approaches"]
ARR --> AR2["sum_of_array/ β 5 approaches"]
ARR --> AR3["largest_element/ β 6 approaches"]
MTH --> MT1["factorial/ β 4 approaches"]
MTH --> MT2["maximum_of_2_numbers/ β 6 approaches"]
MTH --> MT3["add_2_numbers/ β 6 approaches"]
MTH --> MT4["Armstrong_number_check.py"]
Each file in LearnXinY/ is self-contained. Open any file and run it, or just read it β
all examples are written as expressions and print statements you can follow top to bottom.
python LearnXinY/Primitives/numbers.py
python LearnXinY/Collections/lists.py
python LearnXinY/Classes/inheritance.pyFor the algorithm files, compare the approaches side by side to see the trade-offs between readability, performance, and Python idiom.
Tip
One approach in Mathmatical/factorial/ requires NumPy. Install it first with:
pip install numpyThe comment depth scales with topic complexity β purposely pedagogical, not pedantic:
| Level | Topics | Comments focus on⦠|
|---|---|---|
| π’ Rudimentary | Primitives, Variables | What each line does |
| π‘ Intermediate | Collections, ControlFlow | Why a pattern is used, what pitfall it avoids (e.g. mutable default arguments, falsy-value traps) |
| π΄ Advanced | Functions, Classes | When to reach for a technique and what its trade-offs are (e.g. when generators beat list comprehensions, when __slots__ saves memory, how MRO cooperates in multiple inheritance) |
Important
The Advanced tier (Functions, Classes) is where the most educational density lives. Don't skip the comments β they're half the point.
Full attribution details (click to expand)
-
Core examples transcribed from Learn X in Y Minutes β Python, Β© its contributors (Louie Dinh, Steven Basart, Andre Polykanine, and others). Licensed under Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0).
-
Original supplemental examples (marked co-authored with Claude in each file) Β© quadstronaut & Claude (Anthropic), also released under CC BY-SA 3.0.
-
Algorithm files in
Arrays/,Lists/,Textual/, andMathmatical/are original implementations by the repository contributors, released under CC BY-SA 3.0.
Important
This repository will always remain Creative Commons. No proprietary content will be added.
This is a Python-only repository for educational purposes. Contributions that add new Python examples, fix errors, or improve comments are welcome.
Note
Please keep the same commenting style and CC BY-SA 3.0 license header in new files.