MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / modify

Function modify

projects/Merge PDFs/main.py:14–40  ·  view source on GitHub ↗
(pdfs, type)

Source from the content-addressed store, hash-verified

12
13# modify PDF list based on type (exclude/include)
14def modify(pdfs, type):
15 pdf_selections = input(
16 "\nEnter the PDF filenames which should be excluded/included from the list separated by a SPACE:\n> "
17 ).split()
18
19 # store user's selections
20 final_selections = []
21
22 # check if files exist
23 for selection in pdf_selections:
24 if selection not in pdfs:
25 print(
26 f"\n❗️ {selection} does not exist in this directory! Skipping it...\n"
27 )
28 else:
29 print(f"\n❌ Removing '{selection}' from merger...")
30 final_selections.append(selection)
31
32 # include/exclude PDFs
33 for selection in final_selections:
34 if type == "exclude":
35 pdfs = list(filter(lambda x: x != selection, pdfs))
36 else:
37 pdfs = list(filter(lambda x: x == selection, pdfs))
38
39 # return modified list
40 return pdfs
41
42
43if __name__ == "__main__":

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected