I need two different ways for getting the second highest value of an int from a list by just using one for loop and the Len() method. No other functions are allowed for my approach.
sorted(numbers)[-2]
This was my approach, but as you can see I used another function than just a for loop and Len()
How can I get the same result as with my code above just using the allowed functions.
You can use the following function -
While traversing through the numbers -
The above is assuming
len(nums) > 2andsecond_highest([2, 2, 1]) -> 2, if you want it to be1instead, you can replace secondelifcondition withelif second < x and first != x.