How to check if any item from a list of strings is in a big string?

inkhorn matt.dubins at sympatico.ca
Thu Jul 16 09:17:27 EDT 2009


Hi all,

This was more a question of programming aesthetics for me than one of
great practical significance.  I was looking to perform a certain
function on files in a directory so long as those files weren't found
in certain standard directories.  In other words, I was using os.walk
() to get multiple root directory strings, and the lists of files in
each directory.  The function was to be performed on those files, so
long as certain terms weren't in the root directory string.

In actuality, I could have stuck with the helper function I created,
but I'm always curious to see how well multiple lines of code can turn
into fewer lines of code in python and retain the same functional
value :)

Matt

On Jul 15, 6:46 am, denis <denis-bz... at t-online.de> wrote:
> Sure, Aho-Corasick is fast for fixedstrings; but without real
> numbers / a concrete goal
>
> > > Matt, how many words are you looking for, in how long a string ?
>
> a simple solution is good enough, satisficing.  Matt asked "how to
> make that function look nicer?"
> but "nice" has many dimensions -- bicycles are nice for some tasks,
> Ferraris for others.
>
> Bythewayhttp://en.wikipedia.org/wiki/Aho-Corasick_algorithmhas a
> link to a Python implementation,
> alsohttp://en.wikipedia.org/wiki/Worse_is_Betteris fun.




More information about the Python-list mailing list