Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Replace non-numeric values in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88819] Re: Replace non-numeric values in a list
  • From: Szabolcs Horvát <szhorvat+mathgroup at gmail.com>
  • Date: Sat, 17 May 2008 05:31:57 -0400 (EDT)
  • Organization: University of Bergen
  • References: <200805151150.HAA23460@smc.vnet.net> <g0jkfd$162$1@smc.vnet.net>

Syd Geraghty wrote:
> Hi Adel,
> 
> a really straightforward method would be (assuming your list  
> explicitly contains letters and numbers only as in your example)
> 
> In[1]= list = {a, 1, 2, b, 3};
> 
> In[2]= isletter[a_] := If[LetterQ[ToString[a]], True, False]
> 
> In[3]= newlist = Table[If[isletter[list[[i]]], 0, list[[i]]], {i,  
> Length[list]}]
> 
> Out[4]= {0, 1, 2, 0, 3}
> 

It is not a very good idea to rely on ugly hacks like this ... For 
example, this will fail for {1, 2, Pi} ...


  • Prev by Date: Re: Re: Replace non-numeric values in a list
  • Next by Date: overloading times operator
  • Previous by thread: Re: Replace non-numeric values in a list
  • Next by thread: Re: Replace non-numeric values in a list