Weird behavior in search in a list

Amit Khemka khemkaamit at
Thu Mar 29 14:19:39 CEST 2007

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

> On 3/29/07, Amit Khemka <khemkaamit at> 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 --
Home Page:
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