<br><br><div class="gmail_quote">On Mon, Jul 5, 2010 at 11:58 PM, Shashwat Anand <span dir="ltr">&lt;<a href="mailto:anand.shashwat@gmail.com">anand.shashwat@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br><br><div class="gmail_quote"><div class="im">On Mon, Jul 5, 2010 at 11:24 PM, Vineeth Rakesh <span dir="ltr">&lt;<a href="mailto:vineethrakesh@gmail.com" target="_blank">vineethrakesh@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello all,<br><br>Can some one help me to return a special pattern from a list.<br><br>say list = [&quot;something1.mp3&quot;,&quot;something2.mp3&quot;,&quot;something4.pdf&quot;,&quot;something5.odt&quot;]<br></blockquote>


<div><br></div></div><div>One suggestion. Don&#39;t name a list as list. Use l or List or any other variable name. list is one of the syntax in python.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>now say I just need to return the files with .mp3 extension. How to go about doing this?<br></blockquote><div><br></div><div>&gt;&gt;&gt; list = [&quot;something1.mp3&quot;,&quot;something2.mp3&quot;,&quot;something4.pdf&quot;,&quot;something5.odt&quot;]</div>


</div><div>&gt;&gt;&gt; [i for i in list if i[-4:] == &#39;.mp3&#39;]</div><div>[&#39;something1.mp3&#39;, &#39;something2.mp3&#39;]</div><div><br></div><div>or may be ,</div><div>&gt;&gt;&gt; [i for i in list if os.path.splitext(i)[0] == &#39;.mp3&#39;]  # If you want to deal with file extentions, that is.</div>

</div></blockquote><div><br></div><div>Oops, sorry for the typo.</div><div>It&#39;ll be , </div><div>&gt;&gt;&gt; [i for i in list if os.path.splitext(i)[1] == &#39;.mp3&#39;] </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="gmail_quote">
<div>For smaller case string is good, for obscure patter, you can try regex module.</div><div><br></div><div> ~l0nwlf</div></div>
</blockquote></div><br>