Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    Which python version are you using? Because range returned a list in python 2 and is returning a generator in python 3 ... Commented Nov 16, 2018 at 11:28
  • @quant Python 3, but both examples also contain range Commented Nov 16, 2018 at 11:34
  • Can you post the code you used to time the 2 approaches? Commented Nov 16, 2018 at 11:43
  • @Ev.Kounis have added the time calculation. Commented Nov 16, 2018 at 11:48
  • Possible duplicate of List comprehension vs generator expression's weird timeit results? Commented Nov 16, 2018 at 12:10