Is there any syntax for capturing a result evaluated in a boolean expression? In other words, what result led to the logical value being true?
A concrete example - I want the second highest number in the set, regardless of how often the highest number is duplicated:
nums = [1, 2, 3, 4, 4] h = nums.pop() while nums.pop() == h: pass print(nums.pop())
Obviously returns 2 because 3 evaluated the expression. There is something like:
while (i = nums.pop()) == h:
source share