What is the best way to check if an array / tuple / list only contains items in another array / tuple / list?
I tried the following 2 approaches which are better / more pythonic for different kinds of collections? What other (best) methods can be used for this test?
import numpy as np
input = np.array([0, 1, -1, 0, 1, 0, 0, 1])
bits = np.array([0, 1, -1])
a=np.concatenate([np.where(input==bit)[0] for bit in bits])
if len(a)==len(input):
print 'Valid input'
if not set(input)-set(bits):
print 'Valid input'
Dhara source
share