I was solving some algorithm problems and in one of the solutions saw this expression, but can't figure out what does.
return [b, a][nums.count(a) > len(nums)//2]
In case the whole code is needed
def majorityElement6(self, nums):
if not nums:
return None
if len(nums) == 1:
return nums[0]
a = self.majorityElement(nums[:len(nums)//2])
b = self.majorityElement(nums[len(nums)//2:])
if a == b:
return a
return [b, a][nums.count(a) > len(nums)//2]