3 ms·
Don't be a jerk. OP clearly stated he didn't understand it: > When it's just "if" it goes after the "for", when it's "if/else" it goes, all of it, before. I s
by inanutshellus 5y ago
Don't be a jerk.
OP clearly stated he didn't understand it:
> When it's just "if" it goes after the "for", when it's "if/else" it goes, all of it, before. I still don't understand why it's this way
and discussing it here on HN shouldn't be punished.
...
Back to the topic at hand
...
List comprehensions save you enough syntax to be worth it, IMHO:
mylist=[]
for i in container:
if i > 10:
mylist.append(i*2)
vs
mylist = [x*2 for x in container if x > 10]
... That's a very terse, clean request for work and arguably it's easier to read than "for(int i=0; i<10; i++)", which we've all acclimated to by the end of CS101. I think they're quite worth the trade-off.