old solution answered May 29 '16 at 2:23
What I used to make it happen is by a keyboard simulation tool (not really a programming language but also need scripting).
It recognizes the PPT slides I want to remove and multiple choose them, so I can delete them in one go.
Hope it helps someone has the similar need.
updated solution enlightened by Michael Berk in Mar. 2020
Here is a workable example of a PPTX of 5 slides, only to keep the 3rd and 5th ones.
from pptx import Presentation
def dropSlides(slidesToKeep, prs):
indexesToRemove = [x for x in range(1, len(prs.slides._sldIdLst)+1) if x not in slidesToKeep]
for i, slide in enumerate(prs.slides):
id_dict = {slide.id: [i, slide.rId] for i, slide in enumerate(prs.slides._sldIdLst)}
if i+1 in indexesToRemove:
slide_id = slide.slide_id
prs.part.drop_rel(id_dict[slide_id][1])
del prs.slides._sldIdLst[id_dict[slide_id][0]]
return prs
newPrs = dropSlides([3,5], Presentation("C:\\Slides 1-5.pptx"))
newPrs.save('c:\\Slides_only_3rd_and_5th_kept.pptx')