O
9

TIL my first Python script went from 50 lines to 15

I wrote a script to rename a bunch of files six months ago, and it was a mess of loops and if statements. After learning about list comprehensions last week, I rewrote it and it does the same thing with way less code. Has anyone else had a moment where a new concept made your old work look totally different?
3 comments

Log in to join the discussion

Log In
3 Comments
karenmurray
Was it list comprehensions that made you rethink how you write loops in general? That moment of rewriting old code and seeing it shrink is so satisfying. It makes me wonder what else I'm doing the long way around now that I'll look back on later.
2
luna_craig58
luna_craig581mo agoTop Commenter
Oh totally! I still catch myself writing out full loops sometimes and have to go back and fix them.
5
kai657
kai65722d ago
Absolutely, list comprehensions were a total game changer. I had that exact moment cleaning up some old scraping script where a five line loop turned into one clean line. It makes you look at every for loop now and ask if it's really needed. Honestly half my refactoring is just finding those old patterns and shrinking them down.
3