Ad
  • Custom User Avatar

    @ben-hatcher, excellent explaination. Now I understand this much better.

  • Default User Avatar

    Brilliant explanation, ben-hatcher. I did it davpaez's way, which appears to be faster asymptotically judging by the above discussion, but keeping memory in mind is in top form.

  • Custom User Avatar

    it's a generator expression. Instead of creating a list of all elements it creates an iterable object that returns a single element at a time, which sum() can still operate on. You could also add square brackets and it should still work (because both lists and generator objects are iterable) but will use more memory.