Find first in sequence (simple question)

Larry Bates lbates at swamisoft.com
Mon Sep 13 16:25:31 EDT 2004


One easy way (not tested):

#
# target value you are searching for
# nlist holds list of values to search
#
nlist=[1,3,5,7,9]
target=2
larger_value=None
for value in nlist:
    if value > target:
        larger_value=value
        break

print larger_value

"Neal D. Becker" <ndbecker2 at verizon.net> wrote in message
news:mailman.3255.1095103389.5135.python-list at python.org...
> What is an efficient way to find the first element in a sequence meeting
> some condition?
>
> For example, the first number > x in a list of numbers.
>
>





More information about the Python-list mailing list