Can I assign a value to the left side of a boolean expression (for example, in a while loop)?

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: #Do something with i 
0
source share

Source: https://habr.com/ru/post/1260483/


All Articles