import os label_path = "label" label_files = set([os.path.splitext(file)[0] for file in os.listdir(label_path) if file.endswith(".png")]) data_path = "data" data_files = set([os.path.splitext(file)[0] for file in os.listdir(data_path) if file.endswith(".png")]) txt_files = set([os.path.splitext(file)[0] for file in os.listdir(data_path) if file.endswith(".txt")]) if label_files==data_files: print("data_files") if label_files==txt_files: print("txt_files")