a_list = range(1,10) b_list = range(5, 25) both = [] for i in b_list: for j in a_list: if i == j: both.append(i)