MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Occurrence of a substring inside a list of strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51203] Occurrence of a substring inside a list of strings
  • From: János <janos.lobb at yale.edu>
  • Date: Fri, 8 Oct 2004 02:54:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have a simple list of strings like lst={"abc", "abcd", 
"aabccaddbacdda", "adbacca",....}.  Let's say I have a fragment called 
frag="dba".  I would like to know how many strings in lst contain 
minimum once the fragment frag.

This is what I did:

Length[Flatten[Map[Part[StringPosition[#, frag], All, 1] &,lst] ] ]

Is there a better/faster way to calculate it ?

Thanks ahead,

János
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a 
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: Re: Variance of sample and whole dataset
  • Next by Date: Re: no line PlotStyles with ParametricPlot3D ?
  • Previous by thread: Bode Plots.
  • Next by thread: Re: Occurrence of a substring inside a list of strings