[Tutor] Testing a string to see if it contains a substring

Danny Yoo dyoo at hashcollision.org
Thu Jan 22 02:13:51 CET 2015

How large will your array be in production?

If it going to be very large, you may want to consider a database.
You're simulating a collection of records as an in-memory sequence of
flat strings.  This design won't scale, so if you are working with a
lot of data, you may want to look into a dedicated database.

> This method works really well when the regex date characters are found.
> It returns the value 0 to misc_int1 because the date regex starts at 0
> position.
> I was hoping the .start() method would return a -1 value for the
> instance in which the regex search string is not found.
> That way I could iterate through the elements and retain only the valid
> ones.

With regards to your original question: the return type of a search()
is either a match object, or a None.  So your program's control-flow
logic should be accounting for these two possibilities.  At the
moment, the code assumes that it always gets a match object, but that
assumption doesn't hold and explains why you're seeing run-time error

More information about the Tutor mailing list