Separate CT cuts

Hello everyone,
I have a structure called “ptv” inside the body, and I also have the “skin” structure. I want to separate all CT scans that contain both “ptv” and “skin”. It would be better for me to have an additional 2 or 3 slices on each side as well. I know that this can be done using existing modules, but I need a Python code for this task. Can you help me with that?