Aug-16-2023, 02:24 PM
(This post was last modified: Aug-16-2023, 02:24 PM by carecavoador.)
Greetings, fellow pythonistas.
Considering I have the following filenames:
But, this will not always be the case. I'm frying my brains trying to make this work, but couldn't figure it out.
What I have done so far: tryied to look for matching characters on two filenames and guess what is the prefix. But this will fail if I have lets say only two PANTONE colors, as they will be included in the prefix.
Considering I have the following filenames:
filenames = [ "BCY0649_PURANATTA_120X90MM__ Cyan.tif" "BCY0649_PURANATTA_120X90MM__ Black.tif" "BCY0649_PURANATTA_120X90MM__ Magenta.tif" "BCY0649_PURANATTA_120X90MM__ PANTONE 357 C.tif" "BCY0649_PURANATTA_120X90MM__ PANTONE 465 C.tif" "BCY0649_PURANATTA_120X90MM__ Yellow.tif" ]I need to get the last part of the filenames (Cyan, Magenta, PANTONE 357 C etc). In this case in particular, I can do it easily spliting the string on the double underscores
"__"
.But, this will not always be the case. I'm frying my brains trying to make this work, but couldn't figure it out.
What I have done so far: tryied to look for matching characters on two filenames and guess what is the prefix. But this will fail if I have lets say only two PANTONE colors, as they will be included in the prefix.
def get_filename_prefix(first: str, second: str) -> str: prefix = [] first = first.split() second = second.split() for one in first: for another in second: if one == another: prefix.append(one) return " ".join(prefix)Any better ideas?