import os labels = os.listdir("labels") images = os.listdir("images") lst_labels = [i.split(".")[0] for i in labels] lst_images = [i.split(".")[0] for i in images] print(lst_images) print(lst_labels) print(set(lst_labels) == set(lst_images))