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.

7
  • 7
    Since this is the selected answer, I feel compelled to share an answer to selecting the first element correctly here. In short: usage of next shouldn't be encouraged.
    – Guy
    Commented Jul 7, 2016 at 10:56
  • 4
    @guyarad how is the solution proposed in that answer less "cryptic" than just using next ? The only argument against next (in that answer) is that you must handle an exception; really ? Commented Jan 24, 2018 at 23:34
  • My view is a little different than the time I wrote the comment. I see your point. That's being said, having to handle StopIteration is really not pretty. Better use a method.
    – Guy
    Commented Jan 26, 2018 at 3:25
  • 2
    Does it parse the whole array, or does it stop at the first matching element (very important for efficiency)? Commented Jul 13, 2020 at 16:28
  • 1
    @OlivierPons It stops as soon as it finds a match, if there is one. Commented Apr 11, 2021 at 17:12