Here is a neat one-liner in Python 3 to quickly check if entries from one Python list are available in another Python list. This can also be used to apply other functions.

Code

list1 = ["a","b","c","d"]
list2 = ["b","c","d"]
list3 = ["a","x","z"]

# Check if all entries of list2 are in list1
print(all(value in list1 for value in list2))

# Check if all entries of list3 are in list1
print(all(value in list1 for value in list3))
True
False

Explanation

all(x) is a built-in function that returns True if all entries in the Python list x are True.

The list x is generated with an inline for loop (compound for loop):

(value in list1 for value in list2)

This actually creates a generator instead of a list, but it can be used in the all() function since it has the __iter__() method implemented. If you wanted, you could also convert it to a list by putting brackets around them:

list1 = ["a","b","c","d"]
list2 = ["b","c","d"]
print(type(value in list1 for value in list2))
print(type([value in list1 for value in list2]))
<class 'generator'>
<class 'list'>

This would be the long version:

list1 = ["a","b","c","d"]
list2 = ["b","c","d"]
results1 = []
for value in list2:
    results1.append(value in list1)

list3 = ["a","x","z"]
results2 = []
for value in list3:
    results2.append(value in list1)

print(all(results1))
print(all(results2))
True
False


Could I help? Buy me a drink ! 💙