[Tutor] Pythonwin

Magnus Lycka magnus@thinkware.se
Thu Dec 12 02:58:01 2002


At 18:10 2002-12-11 -0800, Scott Widney wrote:
> >>> L, X = [1,2,4,8,16,32,64], 5

I don't think this improves readability over
L = [1,2,4,8,16,32,64]
X = 5

> >>> if L.index(2**X): print "found at", L.index(2**X)
>... else: print X, "not found"
>...
>  found at 5
> >>>

This is not correct, is it? Try replacing the X value
with 0 or 7 and see what happens. It not a big change
that has to be made though.

 >>> if (2**X) in L: print "found at", L.index(2**X)
... else: print X, "not found"

Try putting it in a for loop:

 >>> L = [1,2,4,8,16,32,64]
 >>> for X in range(-1,8):
...     if (2**X) in L: print "found at", L.index(2**X)
...     else: print X, "not found"


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se