I got a a list of numbers:
l = [1,2,3]
And I want to check if the numbers in that list are inside another list, like this one
l2 = [2,5,1,3,4]
This one should return True
Any ideas? Thanks a ton!
Use sets:
print(set(l) <= set(l2))
# True
From the docs:
set <= other
Test whether every element in the set is in other.
all()
method would check if list 1 is in list 2. For example:
l = [1,2,3]
l2 = [2,5,1,3,4]
status = all(item in l for item in l2)
In this case, status
will be True as 1,2,3
are in l2. I hope, this answers your query.
Try this :-
l = [1,2,3]
l2 = [2,5,1,3,4]
for i in l:
for j in l2:
if i == j:
break
print(True)
The result will be True in the end.