Since we want (I’m assuming) only matches at the same index we can create a **zip** object of paired values.

```
>>> a, b = [5, 9, 23, 12], [1, 9, 3, 12]
>>> c = zip(a, b)
>>> d = []
>>> for m, n in c:
if m == n:
d.append(m)
>>> d
[9, 12]
>>>
```

If you are not familiar with the `zip`

constructor, it essentially merges two or more lists into a list of tuples.

```
>>> c
[(5, 1), (9, 9), (23, 3), (12, 12)]
>>>
```

When we iterate a zip object all we need is enough variables to be able to unpack each tuple, in this case two,

```
for m, n in c:
```

This may be new to you, too. Consider,

```
x = (3, 5, 7, 9)
a, b, c, d = x
print a # 3
print b # 5
print c # 7
print d # 9
```

list objects can be unpacked in the exact same way. Of course the shorter the sequence the more it makes sense to unpack, where a longer sequence is better iterated than unpacked so there are not a lot of variables in play.

At some point you will learn about **comprehensions**, if not already learned. We can write a single line solution to the problem which returns a list…

```
>>> a, b = [5, 9, 23, 12], [1, 9, 3, 12]
>>> [m for m, n in zip(a, b) if m == n]
[9, 12]
>>>
```

It follows that we could write this as a reusable function…

```
def matched_pairs(a, b):
return [m for m, n in zip(a, b) if m == n]
print (matched_pairs([5, 9, 23, 12], [1, 9, 3, 12]))
# [9, 12]
print (matched_pairs([12, 16, 20, 24, 28], [4, 5, 20, 21, 28]))
# [20, 28]
```