Example:
tuple = ("python", "includehelp", 43, 54.23)
AND 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 AND elements.
Input:
tuple1 = (4, 1, 7, 9, 3),
tuple2 = (2, 4, 6, 7, 8)
Output:
(0, 0, 6, 1, 0)
Python provides multiple ways to solve the problem and here we will see some of them working.
Method 1:
One method to solve the problem is by simply computing the AND operation of all elements of tuples using the AND operator in the lambda function and mapping them. This collection is then converted to a tuple using the tuple() method.
Output:
Method 2:
Another method to solve the problem is by using the map() method to map each element of both tuples. And the operation on mapping is done using the iand() method to perform AND operation.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer