[Tutor] Pythonwin

Scott Widney SWidney@ci.las-vegas.nv.us
Wed Dec 11 21:11:02 2002


> -+-+-+-+-+-+-+-+-+-+-+
> 
> L=[1,2,4,8,16,32,64]
> X=5
> 
> found = i = 0
> while i< len(L):
>   if 2 ** X==L(i): break
>   else:
>     i=i+1
> 
> ##if found:
>   print 'at index',i
> else:
>   print X, 'not found'
> 
> 
> -- 

Aren't you glad that the batteries are included! From eleven lines to three:

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


Scott