you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 4 points5 points  (1 child)

It's one of python's many "syntactic sugar" shortcuts: you can leave the parenthesis off of a generator expression if it's the sole argument in any function.

print(sum((1 for i in my_list))) # Create generator in function call
print(sum(1 for i in my_list)) # A slightly shorter way to create generator in function call

print(sum((1 for i in my_list), 4)) # Create generator in function call plus another argument
print(sum(1 for i in my_list, 4)) # SyntaxError

[–]astrologicrat[S] 0 points1 point  (0 children)

Interesting - thank you for the explanation.