captions = [] with open('../SCAN-master/data/f30k_precomp/dev_caps.txt', 'rb') as f: for line in f: captions.append(line.strip().decode('utf-8')) print(len(captions)) #print(captions[:10]) result_captions = [] for index in range(0, len(captions), 5): #print(index) tmp = captions[index:index+5] tmp = tmp + tmp #print(tmp) for count in range(1, 5, 1): for pos in range(0, 5, 1): record = "" for c in range(0, count, 1): record += tmp[pos+c] + " " result_captions.append(record) print(len(result_captions)) with open("../SCAN-master/data/f30k_precomp/shuffle_dev_caps.txt", 'w') as f: for line in result_captions: f.write(line +"\n")