Example:
tuple = ("python", "includehelp", 43, 54.23)
Checking if Given Tuple is True Record or Not
We need to check whether a tuple is a true record or not.
For this, we need to iterate over every element for the record and check if it is a valid record or not. If all are valid print 'true' otherwise 'false'.
Input:
tuple = (true, true, 4 , 1)
Output:
true
In python, we can perform the task in multiple ways using one of the multiple methods that are present in the function.
Method 1:
One method to check if the tuples are True record is by checking if any element is not valid using lambda on map() with not() method.
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 method to check if the tuple is a true record or not is by using the all() method. This will check if each element of the tuple is a true element and return a truthy value based on the result.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer