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 - Tu

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 > To: tutor@python.org > Subject: [Tutor] Help return a pattern from list > Message-ID: > > Content-Type: text/plain; charset="

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Alan Gauld
"Shashwat Anand" 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 extensions the os.pa

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 wrote: > > > On Mon, Jul 5, 2010 at 11:24 PM, Vineeth Rakesh > wrote: > >> 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"] >> >

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 wrote: > 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 other vari

Re: [Tutor] Help return a pattern from list

2010-07-05 Thread Sander Sweers
On 5 July 2010 19:54, Vineeth Rakesh 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? Use os.

[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 _