string index - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: string index (/thread-39466.html) |
string index - DPaul - Feb-22-2023 Hi, Tesseract has a few methods to OCR prayer cards, and for a particular type of document, I need to use a combination of two methods. It presents a problem, that I need to solve efficiently , to affect the processing time as little as possible. It goes like this: names = "johnmarypeterpauljohnaugustusemilianostevenandmanyotherwords" # one long string of words on the card I want to find a particular combination, say name = "pauljohn" . I can easily find out if it is in the names string (if name in names: ) Question: If the statement is "True", I need to know the indexes of all it's corresponding letters in names. "Brute force" is always possible, but there might be a more clever way that eludes me? Paul EDIT: don't bother, it's too simple. I thought you could only string.find() letters. You can string.find(strings)/ and get the index. |