Re: Occurrence of a substring inside a list of strings
- To: mathgroup at smc.vnet.net
- Subject: [mg51223] Re: Occurrence of a substring inside a list of strings
- From: astanoff_otez_ceci at yahoo.fr (astanoff)
- Date: Sat, 9 Oct 2004 04:18:37 -0400 (EDT)
- Organization: Gyptis.org les Linuxiens normaux
- References: <ck5eat$ojs$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
János wrote:
> 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 ?
Count[lst, s_ /; StringMatchQ[s, "*" <> frag <> "*"]]
seems to be faster...
--
0% de pub! Que du bonheur et des vrais adhérents !
Vous aussi inscrivez-vous sans plus tarder!!
Message posté à partir de http://www.gyptis.org, BBS actif depuis 1995.