Home>

There is a list of lists:

p= [
     [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1],
     [4, 5, 6], [4, 6, 5], [5, 4, 6], [5, 6, 4], [6, 4, 5], [6, 5, 4],
     [7, 8, 9], [7, 9, 8], [8, 7, 9], [8, 9, 7], [9, 7, 8], [9, 8, 7],
     [7, 4, 1], [7, 1, 4], [4, 7, 1], [4, 1, 7], [1, 7, 4], [1, 4, 7],
     [8, 5, 2], [8, 2, 5], [5, 8, 2], [5, 2, 8], [2, 8, 5], [2, 5, 8],
     [9, 6, 3], [9, 3, 6], [6, 9, 3], [6, 3, 9], [3, 9, 6], [3, 6, 9], .. ..
    ]

There is user input one digit at a time (i.e. at the beginning the list is empty, then there is one element and then one more, more, more...)

p_ot_p=[1,8,5,2]

Here, the list p has [8,5,2] and the input has [..,8,5,2] what is the method to tell Python that this is a match? Yes, and p_ot_p=[8,5,1,2] and other variations are also a coincidence :( Tell me the algorithm to find a match, please. You can download me directly, do not write code

Thank you!

The order of the elements is not important (i.e. p_ot_p= [2, 5, 8, 1] would also be a match)?

4500zenja2022-01-27 15:59:51

Yes, it will be a coincidence! Edited late.

Vsevoload Polu4ayka2022-01-27 16:03:38

alternatively, if the elements in the lists are unique (not repeated), then you can work with them as with sets and use the issubset method to check for matches

SergFSM2022-01-27 16:04:08

print(list(filter({8,5,2}.issubset, p)))

CrazyElf2022-01-27 16:17:46