[Tutor] Extracting filenames from a List?
Tom Jenkins
tjenkins@devis.com
21 Jan 2002 15:36:59 -0500
On Mon, 2002-01-21 at 15:23, Troels Petersen wrote:
>
> >well, how fast is fast? <grin>
>
> Well - Your quickie is certainly 'fast enough' :) (But won't extract
> filenames that are not in lowercase - but that is solved in a previous
> posting)!
>
really? hrmm.. In
def findJPGs(filenameList):
results = []
for x in filenameList:
#this gives use the iteration over the list
if x[-4:].lower() == '.jpg':
# this checks the last 4 characters
results.append(x)
return results
the x[-4:].lower() will lowercase the last 4 characters and compare them
to '.jpg'.
note that i've switched over to python 2.x and so don't usually import
string, instead calling the string methods directly on the string in
question.
--
Tom Jenkins
Development InfoStructure
http://www.devis.com