问题
Is there a syntax to capture a result evaluated in a Boolean expression? In other words, what was the result that caused the Boolean to be True?
A concrete example - I want the second largest number in a set, regardless of how often the largest number is duplicated:
nums = [1, 2, 3, 4, 4]
h = nums.pop()
while nums.pop() == h:
pass
print(nums.pop())
Obviously returns 2, because the 3 has gone in evaluating the expression. Is there something like:
while (i = nums.pop()) == h:
#Do something with i
来源:https://stackoverflow.com/questions/39855895/can-i-assign-the-value-of-the-left-hand-side-of-a-boolean-expression-e-g-in-a-w