Hey, I got an array with float values from 0 - 120. How can I find the first element over 100 and which element it is?

Recommended Answers

All 5 Replies

for f in arr:
    if f > 100:
        return f

Is that what you wanted?

A slight modification.

for index, item in enumerate(arr):
    if item > 100:
        return index, item

See here for info on lists http://effbot.org/zone/python-list.htm

Edit: Damn, this is probably homework. My mistake. Using enumerate will probably red flag it though.

Thanks, you saved my day.

Yep, homework.

Don't worry, your efforts weren't all wasted. I learned that enumerate thing from you, and I'm using it now to make my code look nicer. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.