T
14
c/coding-for-beginnersspencer_webbspencer_webb12d agoProlific Poster

Question about my first Python script from a month ago

I looked at a simple program I wrote to sort a list of names, and compared it to one I just made that does the same thing. The new one is half as long and way easier to read, just from learning about list comprehensions. Has anyone else had a moment where a single new concept made your old code look totally different?
2 comments

Log in to join the discussion

Log In
2 Comments
nelson.michael
Totally get that. List comprehensions felt like magic when I first learned them. My old loops looked so clunky after that.
5
harris.zara
My friend Sam had a whole folder of scripts that used basic for loops to filter data. After he learned about list comprehensions from a post by @nelson.michael, he rewrote a 15-line mess into one clean line. He said it felt like finally being told the shortcut home after walking the long way for years. His old code looks like a different person wrote it. That one trick just changes how you see the problem.
1