I am trying to remove items from slices(list) whose substring is a part of pic(string) value from status2. I have tried various ways but there is always some issue such as sometimes it doesn't iterate over every item, sometimes it returns the exact same list.
slices = ['face_06_01.png', 'face_B45_06_01.png', 'face_gh_06_01.png', 'face_HJ_06_01.png']
status2 = [{'key': 1, 'pic': 'face_01_01.png', 'status': 2}, {'key': 2, 'pic': 'face__B45_02_01.png', 'status': 2}, {'key': 4, 'pic': 'face_gh_04_01.png', 'status': 2}]
for part in slices:
pic_name = part[:-10]
for status2_pic in status2:
if pic_name in status2_pic['pic']:
slices.remove(part)
break
Output I get:
slices = ['face_B45_06_01.png', 'face_HJ_06_01.png']
Output I want according to the sample data:
slices = ['face_HJ_06_01.png']