Weird behavior in search in a list

Amit Khemka khemkaamit at
Thu Mar 29 14:30:55 CEST 2007

On 3/29/07, Michael Bentley <michael at> wrote:
> On Mar 29, 2007, at 6:51 AM, Su Y wrote:
> >
> > I want find the first number in extend[] which is larger than num, so

> def find(num):
>         # check to make sure there *is* a value greater than num
>         if max(extend) > num:
>                 # then return the smallest value that is greater than num
>                 return min([x for x in extend if x > num])
>         else:
>                 return None

I think OP wants the first value in the list greater than 'num' not
the smallest greater value in the list.

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