News for hackers. Stuff that matters.
Re:PHP: A fractal of bad design by RyanMcGreal on Tuesday April 10, 2012 @10:29AM (#3822293)
> I, for one, hate throwing an exception when an item isn't found. This sucks:

You can always do:

    index = a_list.index(a_value) if a_value in a_list else -1
Re:PHP: A fractal of bad design by anthonyb on Tuesday April 10, 2012 @09:48PM (#3825521)
Why would you do that? You're going to have to have a branch to deal with the -1 further down in your code anyway. Why not just deal with it when it happens:

  if value not in list:
      # value not found
      return
  index = list.index(value)
  # Code to deal with the thing
Re:PHP: A fractal of bad design by ge0rg on Tuesday April 10, 2012 @01:50PM (#3823439)
There is even a built-in for that:

    >>> "foo".find("a")
    -1
Re:PHP: A fractal of bad design by andreasvc on Tuesday April 10, 2012 @06:48PM (#3824892)
No there isn't. The one you cite is for strings, not lists. I've always wondered why lists shouldn't also have find, rindex or replace methods.