Example:
tuple = ("python", "includehelp", 43, 54.23)
List is a sequence data type. It is mutable as its values in the list can be modified. It is a collection of an ordered set of values enclosed in square brackets [].
Example:
list = [3 ,1, 5, 7]
Finding Tuples with positive elements in list of Tuples
We will be traversing all the tuples of the list and then check if all elements of each tuple.
Input:
[(4, 1), (9, -1), (5, -7)]
Output:
[(4, 1)]
Method 1:
To find all the tuples of the list that consist of only positive values. For performing this task, we will use the filter() method and check the condition that all values are positive using the lambda function and all().
Output:
Method 2:
Another method to solve the problem is using the list comprehension technique to find the tuples from the list which consist of only positive elements. We will use all methods to test the condition on all elements of the tuple.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer