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

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 11:02:57 -0500, Pablo Torres N. wrote: > On Thu, Jul 9, 2009 at 22:07, Steven > D'Aprano wrote: >> On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: >> >>> def list_items_in_string(list_items, string): >>>     for item in list_items: >>>         if item in string: >>>        

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

2009-07-16 Thread Pablo Torres N.
On Thu, Jul 9, 2009 at 22:07, Steven D'Aprano wrote: > On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: > >> def list_items_in_string(list_items, string): >>     for item in list_items: >>         if item in string: >>             return True >>     return False > ... >> Any ideas how to make tha

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

2009-07-16 Thread inkhorn
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 mult

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

2009-07-15 Thread denis
Sure, Aho-Corasick is fast for fixed strings; 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 -- bicycle

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

2009-07-14 Thread Scott David Daniels
Nobody wrote: On Tue, 14 Jul 2009 02:06:04 -0300, Gabriel Genellina wrote: Matt, how many words are you looking for, in how long a string ? Were you able to time any( substr in long_string ) against re.compile ( "|".join( list_items )) ? There is a known algorithm to solve specifically this pro

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

2009-07-14 Thread Nobody
On Tue, 14 Jul 2009 02:06:04 -0300, Gabriel Genellina wrote: >> Matt, how many words are you looking for, in how long a string ? >> Were you able to time any( substr in long_string ) against re.compile >> ( "|".join( list_items )) ? > > There is a known algorithm to solve specifically this proble

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

2009-07-13 Thread Gabriel Genellina
En Mon, 13 Jul 2009 10:11:09 -0300, denis escribió: Matt, how many words are you looking for, in how long a string ? Were you able to time any( substr in long_string ) against re.compile ( "|".join( list_items )) ? There is a known algorithm to solve specifically this problem (Aho-Corasic

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

2009-07-13 Thread denis
Matt, how many words are you looking for, in how long a string ? Were you able to time any( substr in long_string ) against re.compile ( "|".join( list_items )) ? (REs are my method of choice, but different inputs of course give different times -- see google regex speed site:groups.google.com / sit

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

2009-07-10 Thread inkhorn
Thanks all!! I found the following to be most helpful: any(substr in long_string for substr in list_of_strings) This bang-for-your-buck is one of the many many reasons why I love Python programming :) Matt Dubins -- http://mail.python.org/mailman/listinfo/python-list

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

2009-07-09 Thread Paul Rubin
inkhorn writes: > def list_items_in_string(list_items, string): > for item in list_items: > if item in string: > return True > return False You could write that as (untested): def list_items_in_string(list_items, string): return any(item in string for item in l

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

2009-07-09 Thread John Machin
On Jul 10, 12:53 pm, Nobody wrote: > On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: > > For one of my projects, I came across the need to check if one of many > > items from a list of strings could be found in a long string. > > If you need to match many strings or very long strings against th

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

2009-07-09 Thread Steven D'Aprano
On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: > def list_items_in_string(list_items, string): > for item in list_items: > if item in string: > return True > return False ... > Any ideas how to make that function look nicer? :) Change the names. Reverse the order o

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

2009-07-09 Thread Nobody
On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: > For one of my projects, I came across the need to check if one of many > items from a list of strings could be found in a long string. If you need to match many strings or very long strings against the same list of items, the following should (

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

2009-07-09 Thread Chris Rebert
On Thu, Jul 9, 2009 at 6:36 PM, inkhorn wrote: > Hi all, > > For one of my projects, I came across the need to check if one of many > items from a list of strings could be found in a long string.  I came > up with a pretty quick helper function to check this, but I just want > to find out if there'

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

2009-07-09 Thread inkhorn
Hi all, For one of my projects, I came across the need to check if one of many items from a list of strings could be found in a long string. I came up with a pretty quick helper function to check this, but I just want to find out if there's something a little more elegant than what I've cooked up