On Mar 17, 4:12 am, "Martin Blume" <[EMAIL PROTECTED]> wrote:
> "7stud" schrieb
>
>
>
> > How about:
>
> > -----------
> > x = [0, 100, 200, 1000]
> > y = -1
> > inserted = False
>
> > for i in range(len(x)):
> >         if(y <= x[i]):
> >                 x.insert(i, y)
> >                 inserted = True
> >                 break
> > if(not inserted): x.append(y)
>
> > print x
> > ------------
>
> You can get rid of the sentinel "inserted" using the
> else clause of the for loop:
>
> for i in range(len(x)):
>         if (y <= x[i]):
>                 x.insert(i, y)
>                 break
> else: x.append(y)
>
> Python is cool :-)
>
> IMHO. HTH.
> Martin

for-else?  Neat.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to