**
labels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
incomingLabels = ['UNREAD','IMPORTANT' 'CATEGORY_PERSONAL', 'INBOX']
**
labels array is static array. How do I check incoming array contains all elemnts of labels array.
My attempts
intersectionOfTwoArrays = list(set(incomingLabels) & set(labels))
if np.array_equal(labels, intersectionOfTwoArrays):
//Do somthing
that attempt not succed because intersectionOfTwoArrays's not ordered same as labels array
Can anyone help me on that?
convert both list into set before doing array_equal to avoid order issue
labels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
incomingLabels = ['UNREAD','IMPORTANT', 'CATEGORY_PERSONAL', 'INBOX']
intersectionOfTwoArrays = list(set(incomingLabels) & set(labels))
if np.array_equal(set(labels), set(intersectionOfTwoArrays)):
# Do somthing
print "match"
alternatively, you could using set method issubset
labels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
incomingLabels = ['UNREAD','IMPORTANT', 'CATEGORY_PERSONAL', 'INBOX']
if set(labels).issubset(set(incomingLabels)):
# issubset true, do something
print "match"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With