-1

I have an if statement:

if lst not in listOfLists:

And this if statement is not catching if the list for example:

lst = [[1, -1, -1, 1, 1], [1, 2, 2, 0, 1], [1, 4, 3, 0, 1], [1, 1, 1, 1, 1]]

is in a list of lists for example:

listOfLists = [[[1, -1, -1, 1, 1], [1, 0, 3, 4, 1], [1, 0, 2, 2, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 3, 0, 4, 1], [1, 0, 2, 2, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 0, 3, 4, 1], [1, 2, 2, 0, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 0, 0, 4, 1], [1, 3, 2, 2, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 3, 4, 0, 1], [1, 0, 2, 2, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 3, 0, 4, 1], [1, 2, 2, 0, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 3, 0, 4, 1], [1, 2, 2, 0, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 0, 3, 0, 1], [1, 2, 2, 4, 1], [1, 1, 1, 1, 1]], [[1, -1, -1, 1, 1], [1, 0, 4, 0, 1], [1, 3, 2, 2, 1], [1, 1, 1, 1, 1]], and so on

I've tried changing the listOfLists to a set, and converting the lst to a tuple in the if statement. I've tried collections, all, and any.

To clarify, lst is definitely in listOfLists, but it's not finding it

jim
  • 13
  • 3
  • 1
    Your `lst` is __not__ in `listOfLists` – gimix Feb 08 '23 at 17:20
  • Do you want to check for `lst` being in `listOfLists` or for _any_ of the lists inside `lst` being in `listOfLists`? – Ignatius Reilly Feb 08 '23 at 17:36
  • i didn't provide the whole listOfLists but lst is definitely in it. I'm checking for lst as a whole being in listOfLists. For some reason, it won't recognize that lst is in listOfLists – jim Feb 08 '23 at 17:48
  • 1
    Again, because `lst` is *not* in `listOfLists`. Order matters. It appears that all the elements of `lst` are in a list contained in `listOfLists`, but that's not the same thing. (Actually, even the lists of `lst` are not present, bu the elements on *those* lists are. You really seem to be thinking of all these lists as sets.) – chepner Feb 08 '23 at 17:58
  • 1
    If you are **sure** that `lst` is in (the whole) `listOfLists`, provide a [mre] with a `listOfLists` that actually contains `lst`, so we can reproduce your problem (or you may find it wasn't actually there). With your example, it doesn't even make sense for us to try anything since we know `lst` is not there anyway. – Ignatius Reilly Feb 09 '23 at 02:58
  • BTW, if I take `listOfLists` from your example and add `lst` to it, it works. – Ignatius Reilly Feb 09 '23 at 02:59

1 Answers1

-1

This code works for me, you likely don't have your list in the big list.

ls = [[1, 2], [3, 4]]
ls = [[1, 2], [3, 5]]
lsls = [ [[1, 2], [3, 4]], [[5,6], [7, 8]] ] 

if ls in lsls:
    print("yes")
else:
    print("not in")

if ls2 in lsls:
    print("yes")
else:
    print("not in")

prints: yes, not in

mrblue6
  • 587
  • 2
  • 19