[Tutor] Tweaking list comprehensions

Alan Gauld alan.gauld at freenet.co.uk
Mon Feb 14 10:09:46 CET 2005


> > I am fine tuning list comprehensions (at least my understandng
> > thereof), and I'm not near a Python interpreter at the moment, so
I
> > was wondering if someone could tell me if I did OK -

> > def approachB(files):
> >
> > isHTML = [filename if filename.endswith('.htm') or\
> >    filename.endswith(.html') for filename in files]
> > return isHTML

The approach is OK but one thing I'd point out is a style issue.
Nor,ally a name like isHTML would indicate a predicate or
flag - that is a boolean value. A list might be better having
a plural name such as HTMLfiles or even just areHTML (which
maintains lowercase first letter convention too!)

Just a nit pick...

Alan G.



More information about the Tutor mailing list