On Sat, 01 Sep 2007 13:37:29 -0600, Michael L Torrie wrote:

> What's wrong, then, with doing:
> 
> if i in list:
>    print list.index(i)

If `i` is in the list this does the linear lookup twice.

> If we were to program this .index() method in some language that
> enforces contracts, like haskell, then we'd say that .index() expects a
> value that exists in the list.  So if you violate the contract, why
> should you expect to *not* get an exception.  Doing it any other way,
> though, makes the code a lot more error prone.

Does Haskell exceptions?  In Haskell I would expect such a function to
return the `Maybe` type.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to