-4

I want to assert two list in Python:

list_a = [1, 2, 3]
list_b = [1, 2, 3, 4, 5]


assert contains(list_a, list_b)  # not working
assert list_a in list_b  # not working
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Geek Panda
  • 11
  • 1
  • Does this answer your question? [How can I verify if one list is a subset of another?](https://stackoverflow.com/questions/16579085/how-can-i-verify-if-one-list-is-a-subset-of-another) – Krishna Dec 22 '22 at 14:15
  • 1
    Define "contains". – Kelly Bundy Dec 22 '22 at 14:16
  • 2
    As Kelly said, your question is unclear. What result do you expect if list A's elements are all present in list B but not in the same order? What about if all of list A's elements are in list B, but list A has some elements with more duplicates than list B? Also, please don't just say "not working" but define what "not working" means. – k314159 Dec 22 '22 at 14:34

1 Answers1

-1

If the order matter you can follow this recipe

In alternative, you should use sets:

# Is list_a a subset of list_b ?
not (set(list_a)-set(list_b))
Glauco
  • 1,385
  • 2
  • 10
  • 20