On Mon, 05 Jul 2010 20:29:02 +0200 tutor-requ...@python.org wrote: > Date: Mon, 5 Jul 2010 13:54:55 -0400 > From: Vineeth Rakesh <vineethrak...@gmail.com> > To: tutor@python.org > Subject: [Tutor] Help return a pattern from list > Message-ID: > <aanlktimtfl0hdrjqrrzjxsyv8vebwehpvz_qdcjg4...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > Hello all, > > Can some one help me to return a special pattern from a list. > > say list = > ["something1.mp3","something2.mp3","something4.pdf","something5.odt"] > > now say I just need to return the files with .mp3 extension. How to > go about doing this? > > Thanks > Vin
I use the fnmatch module: import fnmatch fileList = ["something1.mp3","something2.mp3","something4.pdf","something5.odt"] pattern='*.mp3' for x in fnmatch.filter(fileList,pattern): #do something to your files or list items here thomas _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor