list_b
is shorter. Checking if all elements of list_b are in list_a:list_a = [25,15,40,40,10] list_b = [40,40,10] if all(b in list_a for b in list_b): print('All elements of list_b are in list_a') else: print('Not all elements of list_b are in list_a')If you use the set theorie, it's easier:
list_a = [25,15,40,40,10] list_b = [40,40,10] if set(list_b).issubset(list_a): print("set_b is a subset of set_a") else: print("set_b is not a subset of set_a")A
set
contains only unique elements.The order of elements is not preserved.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!