Is there a smart reason why both these are allowed
sum(x for x in range(5)) sum([x for x in range(5)])
but only the last of these are?
l = x for x in range(5) l = [x for x in range(5)]
In the case of builtins working on iterables, it seems you can omit the [] or () (always? sometimes?). That’s great, but does it not break some rule of consistency?
submitted by /u/scarynut
[link] [comments]
r/learnpython Is there a smart reason why both these are allowed sum(x for x in range(5)) sum([x for x in range(5)]) but only the last of these are? l = x for x in range(5) l = [x for x in range(5)] In the case of builtins working on iterables, it seems you can omit the [] or () (always? sometimes?). That’s great, but does it not break some rule of consistency? submitted by /u/scarynut [link] [comments]
Is there a smart reason why both these are allowed
sum(x for x in range(5)) sum([x for x in range(5)])
but only the last of these are?
l = x for x in range(5) l = [x for x in range(5)]
In the case of builtins working on iterables, it seems you can omit the [] or () (always? sometimes?). That’s great, but does it not break some rule of consistency?
submitted by /u/scarynut
[link] [comments]