0

I'm trying to run simple code for finding second highest number in array 'arr' but second array iterator over 'arr' is not working.

if __name__ == '__main__':
    n = int(input())
    arr = map(int, input().split())

    a1=-101
    a2=-102
    for i in arr:
        if a1<i :a1=i

    for j in arr: 
        print(j)

I expect arr value to be printed but getting ~ no response on stdout ~

Aditya
  • 1
  • 1

2 Answers2

0

If you are on Python 3, map is an iterator (it doesn't give a list). To be able to iterate over it more than once, wrap it in a call to list():

arr = list(map(int, input().split()))
iz_
  • 15,923
  • 3
  • 25
  • 40
0

arr = map(int, input().split()) producinng a generator and iterating over a generator, without make it iterable first, that is why you are getting error.

arr = list(map(int, input().split()))
sahasrara62
  • 10,069
  • 3
  • 29
  • 44