import random domains = ["clipart", "infograph", "painting", "quickdraw", "real", "sketch"] random.seed(42) for domain in domains: with open(domain + '_test.txt', 'r') as f: domain_data = f.readlines() random.shuffle(domain_data) with open(domain + '_test_fold.txt', 'w') as f: f.write("".join(domain_data))