T
27

My Python script went from 15 lines to 3 after I learned about list comprehensions

I was rewriting a data filter from a tutorial in Denver and it just clicked. Has anyone else had a moment where a single concept cleaned up their code a ton?
2 comments

Log in to join the discussion

Log In
2 Comments
ivancoleman
Man, list comprehensions felt like cheating at first. I used to write whole loops just to build a simple list of squares. Now it's just [xx for x in range(10)] and I'm done. It completely changed how I clean up data from APIs. My old scripts look like a different person wrote them.
5
oscarwilliams
Heck, they even saved my bacon when my GPS data needed cleaning up fast.
4