[Tutor] Help return a pattern from list

2010-07-05 Thread Vineeth Rakesh
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 ___

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Sander Sweers
On 5 July 2010 19:54, Vineeth Rakesh vineethrak...@gmail.com wrote: 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?

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Shashwat Anand
On Mon, Jul 5, 2010 at 11:24 PM, Vineeth Rakesh vineethrak...@gmail.comwrote: 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] One suggestion. Don't name a list as list. Use l or List or any

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Shashwat Anand
On Mon, Jul 5, 2010 at 11:58 PM, Shashwat Anand anand.shash...@gmail.comwrote: On Mon, Jul 5, 2010 at 11:24 PM, Vineeth Rakesh vineethrak...@gmail.comwrote: Hello all, Can some one help me to return a special pattern from a list. say list =

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Alan Gauld
Shashwat Anand anand.shash...@gmail.com wrote list = [something1.mp3,something2.mp3,something4.pdf,something5.odt] [i for i in list if i[-4:] == '.mp3'] ['something1.mp3', 'something2.mp3'] Or even easier: [s for s in list if s.endswith('.mp3')] But for the specific case of file

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Thomas C. Hicks
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

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Emile van Sebille
On 7/5/2010 4:19 PM Alan Gauld said... But for the specific case of file extensions the os.path.splitext() is a better solution. If, as the names suggest, the source is the file system, then I'd reach for glob. Emile ___ Tutor maillist -