This is a string: \texample\tDart_181120172410.jpg\tImgCaption\t
Is there anyway to get the Dart_181120172410.jpg and could say to get this substring if only it contains .jpg at the end. The actual string is even longer
This is a string: \texample\tDart_181120172410.jpg\tImgCaption\t
Is there anyway to get the Dart_181120172410.jpg and could say to get this substring if only it contains .jpg at the end. The actual string is even longer
Like this:
s = "a.jpg\tnot.llm\tp.jpg\tc.jpg\te.gif\tnix.txt"
all_jpegs = [x for x in s.split('\t') if '.jpg' in x]
print(all_jpegs)
Output: ['a.jpg', 'p.jpg', 'c.jpg']
guillaume-dedrie made a good point in the comment - this will lead to false positives for
s=some.file\tthisisno.jgp.gif\tsomemore.files. Changing it to
s = "a.jpg\tnot.llm\tp.jpg\tc.jpg\te.gif\tnix.txt\tnot.jpg.gif\tthis.JPG"
better_jpegs = [x for x in s.split('\t') if x.lower().endswith('.jpg')]
print(better_jpegs)
would eleminate that and also handle '.JpG' or '.JPG'