What is wrong in my list comprehension?

Stephen Hansen apt.shansen at gmail.com
Mon Feb 2 13:18:39 EST 2009

> I'm only curious if it's worth cleaning up because the OP's case is one
> where there is more than one way to do it.

I just think at this point ".find" is just not the right method to use;
"substring" in "string" is the way to determine what he wants is all.
".find" is useful for when you want the actual position, not when you just
want to determine if there's a match at all. The way I'd clean it is to
remove .find, personally :) I don't remember the outcome of their discussion
on py-dev, and haven't gotten around to loading up Py3 to test it out :)

I s'pose in certain contexts where catching .index's ValueError is too
expensive and just checking vs -1 is faster and speed is important, .find()
can still be useful. I don't do that much text parsing generally, so don't

> However, that's not the way the world is and I suppose smarter people
> have discussed this before. If there's a link to the discussion, I'd
> like to read it. It's pedantic but fascinating no less.

The thread I remember reading was:


It sorta digressed at a certain point :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090202/72ab381e/attachment.html>

More information about the Python-list mailing list