Little novice program written in Python

Peter Otten __peter__ at web.de
Fri Apr 25 03:21:53 EDT 2008


Rogério Brito wrote:

> i = 2
> while i <= n:
>      if a[i] != 0:
>         print a[i]
>      i += 1

You can spell this as a for-loop:

for p in a:
    if p:
        print p

It isn't exactly equivalent, but gives the same output as we know that a[0]
and a[1] are also 0.

Peter



More information about the Python-list mailing list