where function

Scott David Daniels scott.daniels at acm.org
Sun Mar 18 19:21:14 EDT 2007


vorticitywolfe at gmail.com wrote:
> On Mar 18, 10:48 pm, bearophileH... at lycos.com wrote:
>> [...fine solutions to the problem as asked...]
> Thank you both, a little more cumbersome than I expected, but it does
> the job! Thanks!

The obvious simple near-equivalent is:

     data = range(33,99)
     print data.index(45)

And "generalized":
     data = [x % 9 for x in range(30)]
     result = []
     former = -1
     try:
         while True:
             former = data.index(3, former + 1)
             result.append(former)
     except ValueError:
         print result
     else:
         print 'Nothing found'

-- 
--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list