0

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!

3 Answers3

1

Use sets:

print(set(l) <= set(l2))
# True

From the docs:

set <= other
Test whether every element in the set is in other.

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
0

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.

Vidip
  • 162
  • 1
  • 2
  • 13
0

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.