Coloring the elements of a list with different colors

Hi friends,

How do I have the main list with different colors?

Thank you so much for your time.

Alex,

Please post code, not images.

mainList = {12, 14, 8, 0, 33, 17, 5, 10};
listRed = {12, 8, 0, 10};

If[MemberQ[listRed, #], Style[#, Red], #] & /@ mainList

listBlue = Complement[mainList, listRed];
colorMap = AssociationMap[Red &, listRed]~Join~AssociationMap[Blue &, listBlue]

Style[#, colorMap[#]] & /@ mainList

Here is another way:

mainList /.
{n_Integer?(CurryApplied[2][MemberQ][listRed])  :> Style[n, Red],
 n_Integer?(CurryApplied[2][MemberQ][listBlue]) :> Style[n, Blue]}

Thank you so much, Rohit and Gustavo :slight_smile:

Hi Gustavo,

+1, nice use of PatternTest and CurryApplied.