Get File name from a dash delimited string in python lambda

Viewed 131

I have a bunch of file name like this in s3

1623130500-1623130500-Photo-verified-20210631-0-22.csv.gz
1623130500-1623130500-Add-to-cart-20210631-0-4.csv.gz 

with lambda python code can I separate only Photo-verified / Add-to-cart from the above?

I need a solution which give me file name on runtime from above kind of string

1 Answers

I think you are asking how to extract either Photo-verified or Add-to-cart from the above strings.

You can split on - and then extract the portion you want. Basically, you don't want the first two parts or the last 3 parts, so use:

filename.split('-')[2:-3]

That will return a list with:

['Photo', 'verified']

You could then join() them together using:

'-'.join(filename.split('-')[2:-3])

This would give:

Photo-verified

On the second string, it would give:

Add-to-cart
Related