Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to determine the equality of two data sets in python?

Do you know a simpler way to achieve the same result as this? I have this 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))

I also tried with this:

if (color1 + color2 =="blueyellow" or color1 + color2 =="yellowblue")
like image 637
user2517985 Avatar asked Sep 30 '16 00:09

user2517985


People also ask

What is the best way to compare two data sets?

A Dual Axis Line Chart is one of the best graphs for comparing two sets of data. The chart has a secondary y-axis to help you display insights into two varying data points.

How do you check for equality in Python?

Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.

How do you check if two variables are equal in Python?

Use the == operator to test if two variables are equal.


1 Answers

You can use sets for comparison.

Two sets are equal if and only if every element of each set is contained in the other

In [35]: color1 = "blue"

In [36]: color2 = "yellow"

In [37]: {color1, color2} == {"blue", "yellow"}
Out[37]: True

In [38]: {color2, color1} == {"blue", "yellow"}
Out[38]: True
like image 86
Mazdak Avatar answered Oct 19 '22 05:10

Mazdak