I have a following list
list = ['Bucket1', 'ranbuck0', 'ranbuck1', 'ranbuck2', 'ranbuck3', 'ranbuck4', 'ranbuck5', 'ranbuck6', 'ranbuck7', 'ranbuck8', 'ranbuck9']
You could use the list comprehension syntax of Python:
new_list = [_ for _ in list if 'ranbuck' in _]
Instead of the
_s you could also introduce your own variable name for the temporary variable inside the list comprehension. Instead of
'ranbuck' in _ you could also write down another condition whether this element of the list should be in the new one or not.