import os train_20_exs = [] label_file = open("train_20.csv", "r") for line in label_file: line_list = line.strip().split(",") train_20_exs.append(line_list[0]) label_file.close() train_60_exs = [] label_file = open("train_60.csv", "r") for line in label_file: line_list = line.strip().split(",") train_60_exs.append(line_list[0]) label_file.close() for i in train_60_exs: if i in train_20_exs: print(i)