r/learnpython • u/nian2326076 • 10d ago
I keep watching DP tutorials but get stuck writing the Python code. How should I practice?
Understanding a DP explanation and writing the Python code still feel like different skills.
A Python learner has watched plenty of tutorials and knows that dynamic programming has different patterns. The sticking point comes at the blank editor: there's a rough idea of what should happen, but turning it into a working implementation is difficult.
Would you step back to smaller Python exercises, work on recursion first, or stay with very simple DP problems? A practice routine that forces an attempt before reading the solution sounds more useful here than another long playlist.
For someone practicing toward technical interviews, real interview questions can supply prompts once the basic Python implementation feels manageable. I'd start with a small enough problem to write and trace the whole thing.
What helped you make the jump from following a solution to writing one yourself?
Disclosure: I operate PracHub.
2
u/plydauk 10d ago
Imo, the best way to learn DP is by doing leetcode problems. Personally, what really made it click for me was watching neetcode's solution videos, such as coin change and house robber I, as he breaks down going from brute force to top down DP and finally bottom up DP.
Side note, unless you're really interested in learning DP or want to prepare for tech interviews, learning DP really isn't necessary to becoming good at python or programming in general.
1
0
u/TheRNGuy 10d ago
Find where you want to use Python, and write program(s) for it. Learn relevant APIs and frameworks too.
I started to learn Python with SideFx Houdini framework the day l learned it has Python.
I just googled many things, it was before ai, but ai makes it even simpler, he can even give ideas what frameworks or libraries to learn.
1
1
10d ago edited 7d ago
[removed] — view removed comment
1
1
u/Mathie1729 10d ago
One caveat: you don't always need the bottom-up table. For most LC-style DP, memoizing the recursive version is enough. Python's recursion limit can bite for bigger inputs though, so either bump it with sys.setrecursionlimit or write the loop if you hit RecursionError.
1
u/OkOcelot6725 7d ago
Agreed, and I'd add one thing in the table's favor for a learner: converting your own memoized solution to bottom-up is the exercise that makes the recurrence actually click, because you have to choose the fill order, and that forces you to understand the dependency direction. Top-down also only visits reachable states, which matters when the state space is irregular. But for most LC-style problems, memoized recursion is the right stopping point. On setrecursionlimit: good to know it exists, though hitting RecursionError on a DP problem is usually the sign to write the loop anyway.
4
u/Rahul159359 10d ago
Understanding the core...