feature request: a better str.endswith
Michele Simionato
mis6 at pitt.edu
Mon Jul 21 13:18:57 EDT 2003
chrisperkins37 at hotmail.com (Chris Perkins) wrote in message news:<45228044.0307210522.1ef95144 at posting.google.com>...
> mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0307200721.16ef2ea1 at posting.google.com>...
> > Oops! My mistake, I forgot the islice; it should be
> >
> > the=lambda pred,seq: list(itertools.islice(itertools.ifilter(pred,seq),0,1))
> >
> > in such a way that we exit at the first hit, otherwise one could just use
> > the standard "filter".
>
> How about:
>
> def the(pred,seq): return True in itertools.imap(pred,seq)
>
> if you really want to use the name "the" ("any" makes much more sense to me).
>
> Chris
That's a good idea, indeed. BTW, in this context I feel that
if the(filename.endswith, ('.jpg','.jpeg','.gif','.png')):
dosomething()
is more clear than
if any(filename.endswith, ('.jpg','.jpeg','.gif','.png')):
dosomething()
which is confusing to me since it seems "any" is referred to "filename"
whereas it is referred to the tuple elements.
M.S.
More information about the Python-list
mailing list