Python strip or remove part of path [closed]

I am looking to remove part of a file path and leave only the file name as seen below

file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.35.47.jpg, file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.36.13.jpg, file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.36.23.jpg

I would like the end result to be as follows

2021-08-31 10.35.47.jpg, 2021-08-31 10.36.13.jpg, 2021-08-31 10.36.23.jpg

Thanks for any insight

Answer

I’m assuming that your input data is just several strings. You can convert them to Path objects which offer rich interactions:

from pathlib import Path

paths = [
    'file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.35.47.jpg',
    'file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.36.13.jpg',
    'file:///storage/emulated/0/memento/files/329403216/2021-08-31 10.36.23.jpg'
]
filenames = [Path(p).name for p in paths]

gives

['2021-08-31 10.35.47.jpg', '2021-08-31 10.36.13.jpg', '2021-08-31 10.36.23.jpg']