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'Apranoste...@remove.this.cybersource.com.au 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

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

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 -- bicycles are

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 problem

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

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 denis-bz...@t-online.de 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

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

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

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, inkhornmatt.dub...@sympatico.ca 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

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 Paul Rubin
inkhorn matt.dub...@sympatico.ca 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

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 of the

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 nob...@nowhere.com 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