I want to compare two Python lists, \'A\' and \'B\' in such a manner that I can find all elements in A which correspond to the same number in B
I think you can use this code:
A = [5, 7, 9, 12, 8, 16, 25]
B = [2, 1, 3, 2, 3, 1, 4]
d = {}
for a, b in zip(A, B):
    d.setdefault(b, [])
    d[b].append(a)
for k, v in sorted(d.items()):
    print('{} corresponds {}'.format(v, k))
Each key of the dictionary will be an element of B, and its associated value will be the list you want.