It's easier to test whether a 5 occurs before a 3 if they are strings, rather than tuples; so we can use ''.join
to convert them to strings.
>>> data = [('3', '3', '3'), ('3', '3', '5'), ('3', '5', '3'), ('3', '5', '5'), ('5', '3', '3'), ('5', '3', '5'), ('5', '5', '3'), ('5', '5', '5')]
>>> [r for r in data if '53' not in ''.join(r)]
[('3', '3', '3'), ('3', '3', '5'), ('3', '5', '5'), ('5', '5', '5')]
This assumes you only want to test for a 5 immediately before a 3, and won't work for more general cases where the strings in the tuple could e.g. be '53'
themselves. But it's sufficient for your example.
A more general solution is to use a regex, and join on a character like ,
which none of the strings will contain:
>>> data = [('5', '3', '1'), ('53', '1', '1'), ('5', '1', '3')]
>>> import re
>>> pattern = re.compile('(^|,)5,(.*,)*3(,|$)')
>>> [r for r in data if not pattern.search(','.join(r))]
[('53', '1', '1')]
Here the pattern (^|,)5,(.+,)*3(,|$)
matches a 5 either at the start or after a ,
, followed by a comma, followed by any number of things ending with commas, followed by a 3 which is either before a comma or the end of the string.