def keep_pages(doc: Doc, pages) -> Doc:
    """Keep one (an int) or more (a set of int) pages and remove the others."""
    n = number_pages(doc)
    if type(pages) != set:
        pages = {pages}
    del_pages = set(range(n)) - pages
    new_doc = remove_pages(doc, del_pages)
    return new_doc
Keep one (an int) or more (a set of int) pages and remove the others.
pdfsyntax/docstruct.py