Search code examples
pythonarrayslogic

If (item1,item2) in A or B or C


Can't find any similar questions online, would appreciate the help. I would like to find out if two values appear in any lists. For example, I have

A = [1, 3, 5, 4]
B = [5, 7, 9, 0]
C = [2, 7, 3, 9]

Are there any quick methods to check if [1, 2] is present anywhere in order (consecutively) in the lists?

Furthermore, is there a way to check which list it appears in? e.g. for [7,3] it'd return C


Solution

  • Something like

    any([(1, 2) in zip(lst, lst[1:]) for lst in [A, B, C]])