On Mon, 05 Jul 2010 20:29:02 +0200
[email protected] wrote:
> Date: Mon, 5 Jul 2010 13:54:55 -0400
> From: Vineeth Rakesh <[email protected]>
> To: [email protected]
> Subject: [Tutor] Help return a pattern from list
> Message-ID:
> <[email protected]>
> 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 - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor