Example:
tuple = ("python", "includehelp", 43, 54.23)
Elementwise AND operation in Tuple
We will seek each element of both tuples and perform AND operations on the same index. And return all the resultant values of the AND operation.
Input:
tup1 = (3, 1, 4), tup2 = (5, 2, 6)
Output:
(1, 0, 4)
Method 1:
One method to perform AND operation on each element of the tuple is by using generator expression for performing the AND operation and zipping together both the tuples using the zip() method.
Output:
Method 2:
Another approach that can solve the problem is by using "iand" to perform an extended logic of the AND operation and map it using map() and 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