I am recently solving a coding problem. It ask me to move all 0s in one array to the end of the array. Like [0, 1, 1, 0, 0, 1]->[1, 1, 1, 0, 0, 0].
The reality is there could be any type of data in the original array, for example, [0, "A", 1 , None, False, True, 0, 0, 20, 1, 0.0]
what I am doing is looping the array, compare if it is 0, if it is, put it into another array. If it is not, increase the counter, at the end put the same amount of 0s as the counter. However, it treats the Boolean Value False as 0, so I can't do this, I am just curious if there is a way that can separate False from 0, and put into another array as False in Python. Thanks.
Falseis implemented as0but has an other type. So, check value and type!isinstance(True, int)isinstance()check for supertypes as well. Usetype(False) == intinstead.