I have a list of tuples, each containing two integers followed by a string. I would like to filter out substrings from this list but base it on the first two integers of the tuple and not the string itself.
For example
[(0, 7, 'Lorenzo'), (0, 16, 'Lorenzo Malburto'), (3, 7, 'enzo'), (8, 16, 'Malburto'), (9, 13, 'albu'), (24, 32, 'American'), (25, 32, 'merican'), (33, 50, 'singer-songwriter'), (34, 50, 'inger-songwriter'), (44, 47, 'wri'), (44, 50, 'writer'), (53, 61, 'Malburto'), (54, 58, 'albu'), (90, 97, 'Lorenzo'), (93, 97, 'enzo')]
I would like the final list to be
['Lorenzo Malburto', 'American', 'singer-songwriter', 'Lorenzo', 'Malburto']
I duplicated the list and I tried to check, for each tuple, that the string element was a substring for any of the other strings and was also not equal to the string
for sub in duplicates:
if any(sub in s and sub!= s for s in original_list):
#further actions
but that resulted in
['Lorenzo Malburto', 'American', 'singer-songwriter']
With 'Lorenzo' and 'Malburto' missing. That is why I was wondering if this can be done based on the integers. This way 'enzo' would be filtered out because 3 - 7 is contained in the range of 0 - 16 that is 'Lorenzo Malburto' but one of the 'Lorenzo' won't be filtered out because 90 - 97 isn't.
How could this be achieved? Or is there a smarter way to go about this?