T
8

My buddy's 30 minute Python tip saved me a full afternoon of data cleanup

He said just use a list comprehension and a lambda instead of a for loop, and I thought he was overcomplicating it, but after trying it on a 2,000 row CSV from the city's open data portal, it ran in like 45 seconds instead of 20 minutes. Has anyone else found a one-liner that made them feel dumb for doing it the long way?
1 comments

Log in to join the discussion

Log In
1 Comment
drew_thomas9
That whole "ran in 45 seconds instead of 20 minutes" part hit close to home. My buddy Mark was cleaning up some survey data for his small business and he'd written this giant loop that just crawled. He was complaining about it over coffee, and I told him to try a list comprehension, nothing fancy. He texted me later that night saying the same thing, it felt like cheating. He said he almost felt guilty for how easy it was, like he'd been doing manual labor when there was a power tool sitting in the garage the whole time. Now he refuses to write a for loop unless he absolutely has to, and honestly I can't blame him.
2