enumerate is an iterator. Iterators can only be used once; after that, they're empty.
The easy (and idiomatic) solution is to just make a new enumerate iterator for each loop:
def miniMaxSum(arr):
maxNum = 0
indexMax = -1;
for a,b in enumerate(arr):
if b > maxNum:
maxNum = b
indexMax = a
for index,number in enumerate(arr):
print("hello")
If you need to use an iterator more than once, you can save it to a list, and then reuse the list. Just change this line
eArr = enumerate(arr)
… to this:
eArr = list(enumerate(arr))
In this case, there's no reason to do that. You'd just be wasting memory building the list. (As for speed, it's probably a little faster for very small lists, but slower for very big ones—but it probably doesn't matter either way for your code.) But there are cases where it's useful, so it's worth knowing how to do.
arr?enumerateis an iterator. Iterators can only be used once; after that, they're empty.eArris anenumerate object: an iterator, not a list. You already consumed all generated data in the first loop. There is nothing left for the second loop. Solution: convert the iterator to a listeArr = list(enumerate(arr)).