4 ms·
I would write it like this, to avoid constructing the immediate list: sum_of_squares = sum(x*x for x in arr) This makes use of https://www.python.org/dev/
by FreeFull 10y ago
I would write it like this, to avoid constructing the immediate list:
sum_of_squares = sum(x*x for x in arr)
This makes use of https://www.python.org/dev/peps/pep-0289/ https://www.python.org/dev/peps/pep-0289/
- brianwawok 10y agoThanks for the link, this is good to know.