nums = [1,2,3]
sum(2*x for x in nums)
と書けることを知らなかったのでメモ。
実際は
(2*x for x in nums)
というジェネラータが作られ、関数に渡されているだけで、
sum((2*x for x in nums))
と同じ。
Go to list of users who liked
More than 5 years have passed since last update.
nums = [1,2,3]
sum(2*x for x in nums)
と書けることを知らなかったのでメモ。
実際は
(2*x for x in nums)
というジェネラータが作られ、関数に渡されているだけで、
sum((2*x for x in nums))
と同じ。
Register as a new user and use Qiita more conveniently
Go to list of users who liked