I have some pictures in the folder I want to pair so I can add them to my slide with iterative fashion. I want to pair pictures ending with mp ones to bp ones. One caveat is that there are multiple pictures ending with bp and bp so that adding logical check would be feasible.
lets say we have a pictures in the folder
I want to pair 1_birds_bp.png to other pictures starting with 1 and ending with mp
so that the pair should look like #expected result
('D:\\test\\1_birds_bp.png', 'D:\\test\\1_eagle_mp.png')
('D:\\test\\1_birds_bp.png', 'D:\\test\\1_hawk_mp.png')
('D:\\test\\1_birds_bp.png', 'D:\\test\\1_owl_mp.png')
and for reptile group
('D:\\test\\2_reptile_bp.png', 'D:\\test\\2_crocodile_mp.png')
('D:\\test\\2_reptile_bp.png', 'D:\\test\\2_snake_mp.png')
So by following this post I tried
def image_pairs(folder):
bp, mp = [], []
for image_path in glob.glob(folder + '/*.png'):
if "bp" in image_path:
bp.append(image_path)
elif "mp" in image_path:
mp.append(image_path)
for pair in zip(bp, mp):
print(pair)
#yield pair
but I can pair the only
('D:\\test\\1_birds_bp.png', 'D:\\test\\1_eagle_mp.png')
('D:\\test\\2_reptile_bp.png', 'D:\\test\\1_hawk_mp.png')
how can achieve this ?

Aucun commentaire:
Enregistrer un commentaire