Re: list.index crashes when the element is not found

2008-05-03 Thread Erik Max Francis
Jeff wrote: The generally used idiom for that is: lst = ['a', 'b', 'c'] if 'a' in lst: foo = lst.index('a') It's not a very good idiom, since it iterates over the list twice unnecessarily: first, to see if the object is in the list; then, to find the index of that object. That's pointle

Re: list.index crashes when the element is not found

2008-05-03 Thread s0suk3
On May 2, 3:26 pm, TkNeo <[EMAIL PROTECTED]> wrote: > On May 2, 2:49 pm, Jeff <[EMAIL PROTECTED]> wrote: > > > The generally used idiom for that is: > > > lst = ['a', 'b', 'c'] > > if 'a' in lst: > > foo = lst.index('a') > > Jeff - Gracias !! > > I am fairly new to python. Thanks for the example

Re: list.index crashes when the element is not found

2008-05-02 Thread TkNeo
On May 2, 3:09 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On May 2, 3:04 pm, TkNeo <[EMAIL PROTECTED]> wrote: > > > > > On May 2, 1:58 pm, Nick J Chackowsky <[EMAIL PROTECTED]> > > wrote: > > > > TkNeo wrote: > > > > WHAT ? > > > > > This is crazy > > > > Crazy like a fox? > > > > a = [1, 2, 3]

Re: list.index crashes when the element is not found

2008-05-02 Thread TkNeo
On May 2, 2:49 pm, Jeff <[EMAIL PROTECTED]> wrote: > The generally used idiom for that is: > > lst = ['a', 'b', 'c'] > if 'a' in lst: > foo = lst.index('a') Jeff - Gracias !! I am fairly new to python. Thanks for the example code snippet above. It is the same amount of code as receiving -1 and

Re: list.index crashes when the element is not found

2008-05-02 Thread George Sakkis
On May 2, 3:04 pm, TkNeo <[EMAIL PROTECTED]> wrote: > On May 2, 1:58 pm, Nick J Chackowsky <[EMAIL PROTECTED]> > wrote: > > > > > TkNeo wrote: > > > WHAT ? > > > > This is crazy > > > Crazy like a fox? > > > a = [1, 2, 3] > > try: > > a.index(99) > > except: > > a.append(99) > > finally:

Re: list.index crashes when the element is not found

2008-05-02 Thread Jeff
The generally used idiom for that is: lst = ['a', 'b', 'c'] if 'a' in lst: foo = lst.index('a') -- http://mail.python.org/mailman/listinfo/python-list

Re: list.index crashes when the element is not found

2008-05-02 Thread Larry Bates
TkNeo wrote: On May 2, 1:58 pm, Nick J Chackowsky <[EMAIL PROTECTED]> wrote: TkNeo wrote: WHAT ? This is crazy Crazy like a fox? a = [1, 2, 3] try: a.index(99) except: a.append(99) finally: print a.index(99) MY question: which exception should I actually be catching there? **

Re: list.index crashes when the element is not found

2008-05-02 Thread Nick J Chackowsky
TkNeo wrote: On May 2, 1:58 pm, Nick J Chackowsky <[EMAIL PROTECTED]> wrote: TkNeo wrote: WHAT ? This is crazy Crazy like a fox? a = [1, 2, 3] try: a.index(99) except: a.append(99) finally: print a.index(99) MY question: which exception should I actually be catching there? **

Re: list.index crashes when the element is not found

2008-05-02 Thread Jerry Hill
On Fri, May 2, 2008 at 3:04 PM, TkNeo <[EMAIL PROTECTED]> wrote: > ofcouse try catch is going to work but in ideality the index function > should return a -1 and no way in hell crash. It doesn't crash. It raises an exception. This is a pretty fundamental concept of python programming. If you

Re: list.index crashes when the element is not found

2008-05-02 Thread TkNeo
On May 2, 1:58 pm, Nick J Chackowsky <[EMAIL PROTECTED]> wrote: > TkNeo wrote: > > WHAT ? > > > This is crazy > > Crazy like a fox? > > a = [1, 2, 3] > try: > a.index(99) > except: > a.append(99) > finally: > print a.index(99) > > MY question: which exception should I actually be cat

Re: list.index crashes when the element is not found

2008-05-02 Thread Gabriel Genellina
En Fri, 02 May 2008 15:25:13 -0300, TkNeo <[EMAIL PROTECTED]> escribió: WHAT ? This is crazy crashes? Or raises a ValueError exception, which is perfectly normal? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: list.index crashes when the element is not found

2008-05-02 Thread Nick J Chackowsky
TkNeo wrote: WHAT ? This is crazy Crazy like a fox? a = [1, 2, 3] try: a.index(99) except: a.append(99) finally: print a.index(99) MY question: which exception should I actually be catching there? ** Posted from http://www.teranews.com ** -- http://mail.python.org/mailman/listinf

list.index crashes when the element is not found

2008-05-02 Thread TkNeo
WHAT ? This is crazy -- http://mail.python.org/mailman/listinfo/python-list