Re: Mapping a scalar against a list
- To: mathgroup at smc.vnet.net
- Subject: [mg28406] Re: [mg28393] Mapping a scalar against a list
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Mon, 16 Apr 2001 03:29:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
It seems to me that this is one of those problems solutions to which can be multiplied ad infinitum. Here is just one attempt: In[1]:= MyMap[f_, {a_, l_List}] := f @@@ (Hold[a, #] & /@ l) In[2]:= {a, l, f} = {"dog", {"dog", "cat", "mouse"}, f = StringMatchQ}; In[3]:= MyMap[f, {a, l}] Out[3]= {True, False, False} Hold as such plays no role here, you could replace it by lots of other reasonable things. -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ on 01.4.15 1:13 PM, Mark Coleman at mcoleman at bondspace.com wrote: > Greetings, > > I've recently been working on a problem involving determining whether a > given string is contained in a large list of strings. Ideally, the problem > would be solved by a 'Map' function 'M' defined as > > M[f,{a,{b,c,d,...}}]= {f[a,b],f[a,c],f[a,d],...} > > For this particular problem, {a} is a stiring, and {b,c,d,...} is a list of > strings, then f=StringMatchQ. The function 'M' does not appear to match up > against the standard Mathematica list functions. My current solution is to > 'expand' > the list {a} into a list of size Dimension[{b,c,d,...}] and then use > MapThread. But this does not seem particularly elegant, especially if the > list is very large. > > Any suggestions would be most welcome! > > Thanks, > > Mark > > >