0
a = [1,2,3,4,5,6,8]
b = [6,8,9,4,5,3,2,1]

final result should be

c = [6,8,4,5] 

This array contains the same pair of numbers in both arrays - how to write this kind of code in python?

I only known how to create an array with duplicated values

a = [1,2,3,4,5,6,8]
b = [6,8,9,4,5,3,2,1]
c = [x for x in a if x in b]
print (c)
AcK
  • 2,063
  • 2
  • 20
  • 27

1 Answers1

5
>>> [e for t in [t for t in zip(b,b[1:]) if t in zip(a,a[1:])] for e in t]
[6, 8, 4, 5]
Sunitha
  • 11,777
  • 2
  • 20
  • 23