superpollo ha scritto:
Jimbo ha scritto:HelloI am trying to find if there is a string OR list function that will search a list of strings for all the strings that start with 'a' & return a new list containing all the strings that started with 'a'. I have had a search of Python site & I could not find what I am looking for, does a function like this exist?>>> sw = lambda s: lambda t: t.startswith(s)>>> list = ["a string","another one","this is a string","and so is this one"]>>> filter(sw("a"),list) ['a string', 'another one', 'and so is this one'] >>> bye
of course there is a simpler way:
>>> [string for string in list if string.startswith("a")]
['a string', 'another one', 'and so is this one']
>>>
bye
--
http://mail.python.org/mailman/listinfo/python-list
