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?
Use os.path.splitext() to check for the extension and check if it equals the extension you want. For example like below idle session: >>> import os >>> say_list = >>> ["something1.mp3","something2.mp3","something4.pdf","something5.odt"] >>> mp3_list = [x for x in say_list if os.path.splitext(x)[1].lower() == ".mp3"] >>> mp3_list ['something1.mp3', 'something2.mp3'] Greets Sander _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor