wildcard match with list.index()

Arnaud Delobelle arnodel at googlemail.com
Mon Nov 10 14:59:29 EST 2008


Mr.SpOOn <mr.spoon21 at gmail.com> writes:

> Hi,
> is there any way to search elements in a list using wildcards?
>
> I have a list of various elements and I need to search for elements
> starting with 'no', extract them and put in a new list.
> I was thinking about something like:
>
> mylist.index('no*')
>
> Of course this doesn't work.

I have exactly what you need :)

>>> import fnmatch
>>> fnmatch.filter(['baba', 'nono', 'papa', 'mama', 'nostradamus'], 'no*')
['nono', 'nostradamus']
>>>

HTH

-- 
Arnaud



More information about the Python-list mailing list