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.

5
  • 4
    This helps us to avoid try catch! Commented Sep 10, 2018 at 7:45
  • 6
    However, it might double the complexity. Did anybody check? Commented Sep 6, 2019 at 15:58
  • 4
    @stefanct Time complexity is still linear but it will iterate through the list twice. Commented Jan 28, 2020 at 20:55
  • 4
    @ApproachingDarknessFish That is obviously what I meant. Even if pedantically it is the same order of complexity, iterating twice might be a severe disadvantage in many use cases thus I brought it up. And we still don't know the answer... Commented Jan 29, 2020 at 1:50
  • 2
    @stefanct this likely does double the complexity, I believe the in operator on a list has linear runtime. @ApproachingDarknessFish stated it would iterate twice which answers your question, and is right in saying that doubling the linear complexity is not a huge deal. I wouldn't call iterating over a list twice a severe disadvantage in many use cases, as complexity theory tells us that O(n) + O(n) -> O(2*n) -> O(n), ie- the change is typically neglibile. Commented Jun 27, 2021 at 6:48