This project has been created as part of the 42 curriculum by dporhomo.
A comprehensive masterclass transitioning from imperative C-style memory management to highly optimized, idiomatic modern Python.
This repository contains pure Python refactors of the standard Exam Rank 03 exercises. Successfully completed on April 28, 2026, this collection demonstrates how imperative C paradigms—such as double pointers, manual memory allocation (malloc/free), null-terminated buffers, and accumulator loops—translate into highly optimized, clean, and modern Python 3.13 code.
Every solution is strictly typed, heavily optimized for time/space complexity, and entirely compliant with Flake8 linting standards.
| Exercise | Description | Key Pythonic Upgrades |
|---|---|---|
ft_atoi_base.py |
Base-N string to decimal conversion |
int(s, base) standard fallback handling |
ft_list_size.py |
Linked list node counting | Class wrappers, Optional/Union type hinting |
ft_range.py |
Dynamic array allocation | Inclusive stepping (end + step), inline ternaries |
ft_rrange.py |
Native reversed array allocation |
[::-1] duplicate buffers |
hidenp.py |
Subsequence character matching | Stateful iterators (iter()) + short-circuiting all()
|
lcm.py |
Lowest Common Multiple | Euclidean GCD formula unpacking, optimized manual looping |
paramsum.py |
Argument parsing | Native sys.argv off-by-one slicing |
pgcd.py |
Greatest Common Divisor | Instant Euclidean modulo swapping (a, b = b, a % b) |
print_hex.py |
Decimal to base-16 output | Formatted f-strings (f"{val:x}") |
rstr_capitalizer.py |
Strict whitespace-aware capitalization |
enumerate() lookaheads, zero-destructive parsing |
tab_mult.py |
Multiplication tables |
range() sequences + inline formatted f-strings |
fprime.py |
Ascending prime factorization |
Generators (yield), lazy memory snapshots, *.join() |
ft_itoa.py |
Integer to string conversion | Arbitrary precision handling (INT_MIN safe), C-level str()
|
ft_list_foreach.py |
Higher-order mapping | First-class Callables, lambda anonymous operations |
ft_list_remove_if.py |
Conditional node deletion | Sentinel/Dummy Node pattern, automatic garbage collection |
ft_split.py |
Whitespace delimiter parsing | Stateful generators, zero-argument .split() whitespace sweeps |
ft_strmapi.py |
Character-by-character mapping | Immutable generator expressions + chr()/ord() ASCII math |
lst_all_full.py |
Comprehensive List Capstone | Full suite (insertion, sentinel deletion, tuple-unpack bubble sort) |
rev_wstr.py |
Word sequence reversal | Slicing arrays, zero-allocation manual two-pointer traversal |
sort_int_tab.py |
In-place numeric sorting | Timsort (.sort()), Level 4 tuple unpacking swaps |
sort_list.py |
Linked list Gnome sort | In-place pointers, first-class Callable[[int, int], int]
|
Instead of allocating massive buffers in RAM, heavy data generation (like fprime and ft_split) utilizes Generators (yield). This freezes execution state in tiny stack frames, keeping memory footprints near zero regardless of dataset size.
Imperative helpers (ft_atoi, ft_strcmp, ft_putnbr, ft_swap) are completely omitted. They are replaced by native containment checks (in), built-in constructors, and highly optimized C-level standard libraries (math.gcd).
- No Double Pointers (
**head): Linked list mutations explicitly return the new head, mapping references cleanly to variables. - Sentinel Nodes: Edge cases involving deleting or inserting at the absolute head are mitigated using dummy/sentinel nodes (
dummy = Node(None)). - Garbage Collection: Manual sweeps (
free()) are abandoned. Dropping pointers automatically triggers Python's Garbage Collector to sweep orphaned memory.
Temporary swap variables are eradicated. Python's tuple unpacking safely evaluates the right-side expression entirely before updating references on the left:
# Instantly swap values or pointers in memory safely
current.data, current.next.data = current.next.data, current.dataEnsure you are running Python 3.10+ (optimized for 3.13). Most programs accept standard system arguments:
# Run prime factorizer
python3 fprime.py 225225
# Output: 3*3*5*5*7*11*13
# Run hidden string check
python3 hidenp.py "abc" "2altrb53c.sse"
# Output: 1
# Run full linked list capstone tests
python3 lst_all_full.py
To confirm strict adherence to PEP 8 standards:
flake8 . --count --show-source --statistics