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
    There's no way the List Comprehension solution takes ~0.081s just to go through those three elements. How did you measure, exactly? Commented Feb 26 at 12:41
  • 1
    I have used Python’s timeit module and run it multiple times (e.g., 100,000 iterations to ensure meaningful benchmarking.) and compute the average execution time (Approximate). ex: import timeit timeit.timeit('code', setup='import_libraries', number=100000) Commented Feb 26 at 13:32
  • And which Python implementation/version? I was surprised by the listcomp being slower than compress and deque, so I now tried it myself and can't reproduce it. The listcomp takes me ~0.04s and the other two ~0.07s. With CPython 3.13.0. Commented Feb 26 at 14:13
  • My benchmark script for my previous comment. Commented Feb 26 at 14:14
  • I have python 3.12, I have corrected my response by recalculating, there was a typo, Thanks! Commented Feb 27 at 5:54