[Tutor] joker signs?

Michael Janssen Janssen@rz.uni-frankfurt.de
Sat Jan 4 17:38:01 2003


On Sat, 4 Jan 2003, djuro wrote:

> Hello!
>
> for instance:
>
> x = ['ben','sandy','roger','hillary','john','betty']
> a = x.index('ben')
> print a
> ---------
> 0
>
> How to get indexes of all names which begin with "b"  (like    x.index('b*')
> or, find all names that contain "er". Is it possible to do using some joker
> letters like in os prompt?

Hello Djuro,

you're looking for the fnmatch modul. In Python 2.2 you can do:

>>> fnmatch.filter(['ben','sandy','roger','hillary','john','betty'], "b*")
['ben', 'betty']

Michael

>
> Thank you
>
> Djuro
>
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>