вы можете использовать:
train_data = ["img_1.png", "img_2.png"]
test_data = ["image_3.png", "img_4.png"]
val_data = ["img_5.png", "img_6.png"]
image_annotations = [['img_1.png', 432, 662, 554, 749, 'class'],
['img_1.png', 647, 456, 754, 594, 'class'], ['img_2.png', 598, 659, 897,
302, 'class']]
# get a maping with all the img names and their value
d = {}
for e in image_annotations:
d.setdefault(e[0], []).append(e)
# set new values to data variables accordding to dict d
for l in train_data, test_data, val_data:
l[:] = [e for i in l for e in d.get(i, [i])]
print(train_data)
print(test_data)
print(val_data)
вывод:
[['img_1.png', 432, 662, 554, 749, 'class'], ['img_1.png', 647, 456, 754, 594, 'class'], ['img_2.png', 598, 659, 897, 302, 'class']]
['image_3.png', 'img_4.png']
['img_5.png', 'img_6.png']