How can i simplify this condition in python?
<p>Do you know a simpler way to achieve the same result as this?
I have this code:</p>

<pre><code>color1 = input("Color 1: ")
color2 = input("Color 2: ")

if ((color1=="blue" and color2=="yellow") or (color1=="yellow" and color2=="blue")):
            print("{0} + {1} = Green".format(color1, color2))
</code></pre>

<p>I also tried with this:</p>

<pre><code>if (color1 + color2 =="blueyellow" or color1 + color2 =="yellowblue")
</code></pre>

<p>Don't miss the <em>bigger picture</em>. Here is a better way to approach the problem in general.</p>

<p>What if you would define the "mixes" dictionary where you would have mixes of colors as keys and the resulting colors as values.</p>

<p>One idea for implementation is to use immutable by nature <a href="https://docs.python.org/3/library/stdtypes.html#frozenset" rel="nofollow"><code>frozenset</code></a>s as mapping keys:</p>

<pre><code>mixes = {
    frozenset(['blue', 'yellow']): 'green'
}

color1 = input("Color 1: ")
color2 = input("Color 2: ")

mix = frozenset([color1, color2])
if mix in mixes:
    print("{0} + {1} = {2}".format(color1, color2, mixes[mix]))
</code></pre>

<p>This way you may easily <em>scale</em> the solution up, add different mixes without having multiple if/else nested conditions.</p>

python python-3.x if-statement condition simplify