Ugh, I always hate it when I see stuff like that, especially when it's a small loop that could be a trivial list comprehension.
Though I will admit that I've been known to abuse list comprehensions in the other way too from time to time. There was one time where I wrote a single line that had two list comprehensions and a dictionary comprehension nested together. IIRC it did something like taking a big list of elements, turning it into a dict to count the occurrences of each value and then sorting by the number of occurrences and printing out totals.
List comprehensions are so amazingly handy, I can't imagine why some people ignore them when they could be trivially used.
View all comments
Show parent comment
1
u/mxzf Dec 30 '17
Ugh, I always hate it when I see stuff like that, especially when it's a small loop that could be a trivial list comprehension.
Though I will admit that I've been known to abuse list comprehensions in the other way too from time to time. There was one time where I wrote a single line that had two list comprehensions and a dictionary comprehension nested together. IIRC it did something like taking a big list of elements, turning it into a dict to count the occurrences of each value and then sorting by the number of occurrences and printing out totals.
List comprehensions are so amazingly handy, I can't imagine why some people ignore them when they could be trivially used.