Filter a List in Python With List Elements -
i have following list
list = ['bucket1', 'ranbuck0', 'ranbuck1', 'ranbuck2', 'ranbuck3', 'ranbuck4', 'ranbuck5', 'ranbuck6', 'ranbuck7', 'ranbuck8', 'ranbuck9']
is there way filter list , create new list, have elements named "ranbuck". not able figure out way how iterate ranbuck1, ranbuck2 append these in list.
thanks in advance
you use list comprehension syntax of python:
new_list = [_ _ in list if 'ranbuck' in _]
instead of _
s introduce own variable name temporary variable inside list comprehension. instead of 'ranbuck' in _
write down condition whether element of list should in new 1 or not.
Comments
Post a Comment