Check one array's elements contains in another array

arrays, python-2.7

Solution

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"

Problem

** ``` 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?

Original source