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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -