class Solution(object):
def moveZeroes(self, nums):
nums.sort(key =lambda x : 1 if x == 0 else 0)
return nums
My function looks like above.
I don't seem to understand how code key =lambda x : 1 if x == 0 else 0
works.
I also tried to change the lambda function to:
def getKey(item):
if item == 0:
return 1
else:
return 0
But don't seem to understand how key=1 or 0, affects the result.