Example:
tuple = ("python", "includehelp", 43, 54.23)
XOR operation on Tuples
In this program, we are given two tuples. We need to create a Python program to return a tuple that contains the XOR elements.
Sample Input:
tuple1 = (4, 1, 7, 9, 3) , tuple2 = (2, 4, 6, 7, 8)
Output:
(6, 5, 1, 14, 11)
Method 1:
One method to perform the XOR operation on elements of tuples is by using generator expression with the zip() to map the elements of both tuples using the XOR operation and create a tuple with resultant values.
Output:
Method 2:
Another method to solve the problem is by mapping the XOR operation of the tuple elements done using the XOR operator. Then convert the map to a tuple using the tuple() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer