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

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

Is that what you wanted?

Jump to Post

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.

Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.