[Tutor] Tweaking list comprehensions
Alan Gauld
alan.gauld at freenet.co.uk
Mon Feb 14 10:13:41 CET 2005
> > isHTML = [filename if filename.endswith('.htm') or\
> > filename.endswith(.html') for filename in files]
> > return isHTML
>
> No, it should be...
Well spotted, but...
>
> isHTML = [filename for filename in files if
filename.endswith('.htm') or\
> filename.endswith('.html') for filename in files]
> isHTML = [filename for filename in files if
filename.endswith('.htm') or\
> filename.endswith('.html')]
you forgot to remove the last loop!
Oh, and the line continuation slash shouldn't nbe needed since its
inside the []
Alan G.
More information about the Tutor
mailing list