On 5/12/2010 11:33 AM, Aahz wrote:

also, what if the OP intended "words that begin with x" with x a string
(as opposed to a single character) ?

     word[:len(x)] == x

will work in that case.

But that's now going to be slower.  ;-)  (Unless one makes the obvious
optimization to hoist len(x) out of the loop.)

If x were a known literal, then len(x) could be replaced by the actual size. But I admit that that is a nuisance and point of failure. I think comparing start/end strings of variable length or length greater than one is the real justification for the new methods, not the OP's trivial single-char case.

Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to