'Conditional Styling with Dash Bootstrap with IF statement

I'm trying to apply two different colors based on the text value in the column by using Dash bootstrap and some of the HTML components. For example, the table looks like this.

Value

Yes
No
Yes
Yes
No

I want to change the color of the text to green if it's "Yes and to red if it's "No". I tried the following lines but it seems like the if statement doesn't work in this way.

html.Td(
         a["Value"],
         if a["Value"] == "Yes":
              style={"color": "green"},
         else:
              style={"color": "red"},
                                       ) for a in i["Items"]



Solution 1:[1]

try Ternary Operators:

html.Td(a["Value"],
   style={"color": "green"} if a["Value"] == "Yes" else {"color": "red"})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1