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
___
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?
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
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 =
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
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
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 -