Contact: aviboots(AT)netvision.net.il
40,849 questions
53,254 answers
573 users
# Adjacent = two numbers that are next to each other in a list lst = [3, 8, 0, 4, 7, 2, 9, 1] a = 2 b = 9 adjacent = any((lst[i], lst[i + 1]) == (a,b) for i in range(len(lst) - 1)) print(adjacent) ''' run: True '''
# Adjacent = two numbers that are next to each other in a list lst = [3, 8, 0, 4, 7, 2, 9, 1] a = 2 b = 9 adjacent = (a, b) in zip(lst[:-1], lst[1:]) print(adjacent) ''' run: True '''