Weird behavior in search in a list

Amit Khemka khemkaamit at gmail.com
Thu Mar 29 08:19:39 EDT 2007


> On 29 Mar 2007 04:51:00 -0700, Su Y <suyuancn at gmail.com> wrote:
<snip>
> > I want find the first number in extend[] which is larger than num, so
<snip>

> On 3/29/07, Amit Khemka <khemkaamit at gmail.com> wrote:
> Btw a concise way could be:
> def getfirstbigger(num):
>     for i,x in enumerate(extend):
>         if x>num:    return i
>     return len(extend)

I forgot to add that you can as well 'return' the the item (along with
the index), but in case all the items in the list are smaller than the
argument, what return value do you require?
-- 
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list