"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote: > > On 8/23/06, Josiah Carlson <[EMAIL PROTECTED]> wrote: > > > or even > > > > index = 0 > > while 1: > > index = text.find(..., index) > > if index == -1: > > break > > ... > > compared with > > > > index = 0 > > while 1: > > try: > > index = text.index(..., index) > > except ValueError: > > break > > ... > > You are supposed to use the in operator: > > index = 0 > while 1: > if not "something" in text[index:]: > break
This can also lead to O(n^2) running time, causes unnecessary string allocation, memory copies, etc. If I saw that in real code, I'd probably lose respect for the author of that module and/or package. > IMHO, removing find() is good because index() does the same job > without violating the Samurai Principle > (http://c2.com/cgi/wiki?SamuraiPrinciple). It would be interesting to > see the patch that replaced find() with index(), did it really make > the code more cumbersome? Everywhere there is a test for index==str.find(...), needs to be replaced with a try/except clause. That's a cumbersome translation if there ever was one. - Josiah _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
