Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
aList = range (0,20)
for a in aList:
if a < 3:
print (a)
Why is this not good enough? -
flag020328y
-
It's a matter of sanity, more than anything. The type of a comprehension is defined by its enclosing parenthesis. Round for a generator (lazy), square-ish for list, etc.
It wouldn't make sense to have more than one syntax to create the same generator comprehension. It'll be confusing as hell, not to mention the added complexity of the python interpreter. -
meshbag288yABAP does this nicely:
LOOP AT mylist WHERE mylistelement > 3 ASSIGNING <pointer>.
ENDLOOP.
Shame about the rest of it, very verbose :( -
Maybe because they're two completely different things and you having a list comp in the 2nd for loop only makes things O(n^2) ?
-
First one gets a compared to 3 with every loop iteration, second one returns new iterator with only a(s) < 3 from which for loop is iterated through new a(s)
-
elazar10308y@afrometal learn, and then don't use them. filter and especially reduce are not idiomatic Python and are hard to understand.
-
@elazar is it? I usually avoid continue and break as much as possible in C, they feel... kind of goto-y.
-
elazar10308y@Gauthier it's not an arbitrary continue. It's immediately at the beginning, and the meaning is obvious.
-
DrHaXX888yOne thing I really miss in python is being able to use a simple "count++" statement... I know there are more Pythonic ways to do this (also, I fucking hate that word), but this really gets on my nerves as I use this in practically every other language.
-
elazar10308yTo add a new syntactic category so you can do something that you can already do, using 2 characters instead if 3? ☺
Related Rants
Python is such a elegant language, but why can't I have an if-clause on a simple for-statement when I can have it in a list comprehension??
undefined
wk30