Hi Peter,
The "obvious" ways don't work
mylist /. Except[_Integer] :> "Real"
mylist /. _?(Not@IntegerQ[#] &) :> "Real"
both result in "Real" because the pattern matches at level 0. Have to use Replace
and specify a levelspec
Replace[mylist , Except[_Integer] :> "Real", 1]
Replace[mylist , _?(Not@IntegerQ[#] &) :> "Real", 1]
(* {1, "Real", 2, 3, "Real", "Real"} *)
Need to specify the rules individually
mylist /. {_Integer -> "Integer", _Real -> "Real"}
(* {"Integer", "Real", "Integer", "Integer", "Real", "Real"} *)
stringlist
is not a List
of String
,
stringlist = {True,False,False,True,False,False,True,False,True,True,False}
Head /@ stringlist
(* {Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol, Symbol} *)
Since they are either True
or False
Style[If[#, Green, Red]] & /@ stringlist