[Tutor] Is there a prettier way to do this?

Kent Johnson kent_johnson at skillsoft.com
Fri Oct 1 11:51:16 CEST 2004


I think my version does what you want. It will find target text that 
contains all of the search words. The final code is still two nested loops. 
The inner loop reports failure and breaks as soon as it finds a search word 
that is not in the target text. If the loop completes then every search 
word was found and it reports success.

Kent

At 10:53 PM 9/30/2004 -0500, Douglas N. Shawhan wrote:
>The problem is: I think I was unclear stating what the loop is supposed to do!
>
>I need to find *more than one* string fragment per string.
>
>Say I need to verify the existence of the sequences "joe", "bill" and 
>"leon" in a string - but the next time I may need only find "joe" and 
>"bill", which is why I went with the 0, 1 scheme.
>
>It may be better stated as: "How do I find arbitrary numbers of substrings 
>in arbitrary order in a string pythonically?"



More information about the Tutor mailing list