I don't know why but for loop after printing max value from array does not work. But if I remove print(max(arr)) it works fine.
Input:
3 3 3 34 5
Code:
arr = map(int, set(input().split()))
print(max(arr))
for i in arr:
print(i)
Expected output:
34
3
34
5
Output:
34
CodePudding user response:
You have exhausted the iterator returned from map(). Instead, create a list from the map():
arr = list(map(int, set(input().split()))) # <-- add list() around map()
print(max(arr))
for i in arr:
print(i)
Prints (for example):
3 3 3 34 5
34
5
3
34
