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
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
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]
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
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:
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
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?
**
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?
**
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
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
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
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
WHAT ?
This is crazy
--
http://mail.python.org/mailman/listinfo/python-list
13 matches
Mail list logo