3
$\begingroup$

I have a list like this:

list = {0, 0, 0, 1, 1, 1}

I want to color all the 0's in red, but I dont want to count through all the elements, like in my solutions, which seems awefully complicated:

Table[If[list[[x]] == 0, Style[list[[x]], Red], list[[x]]], {x, 1, Length@list}]

How else could I do this without using Table? In other words, a simpler way, if possible.

$\endgroup$
5
$\begingroup$
list /. (0) :> Style[0, Red]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.