3 ms·
False. I have been harshly attacked here on HN for suggesting things like for line in lines - literally been called "stupid". I'm not the only one who looked a
by onphonenow 5y ago
False. I have been harshly attacked here on HN for suggesting things like for line in lines - literally been called "stupid".
I'm not the only one who looked at the recommended examples of the use case here and went, huh?
https://news.ycombinator.com/item?id=17450890 https://news.ycombinator.com/item?id=17450890
Recommended new way:
if any(len(longline := line) >= 100 for line in lines):
print("Extremely long line:", longline)
Old way:
for line in lines:
if len(line) >= 100:
print("Extremely long line:", line)
break
I prefer the old way. These were examples in the PEP!
In your example get_it() might be better as a generator or iterable. A lot of code looks great if you push that type of thing down a bit, and sometimes memory is helped as well. Then you iterate over it, for values in get_it. This keeps python very natural. You start to get a lot of weird line noise type code with := vs the old python style which while a bit longer was basically psudo-code.