hi, I have to check if the vector contains all 0 or 1 and if no exception occurs:
def assert_all_zero_or_one(vector):
if set(vector)=={0}: return 0
if set(vector)=={1}: return 1
raise TypeError
with this exception
assert_all_zero_or_one([1,1,1])
assert_all_zero_or_one([0,0])
assert_all_zero_or_one([1,0,1])
I don't like this solution .. is there a better way to do this with python?
nkint source
share