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 ordered set of values enclosed in square brackets [].
Example:
list = [3 ,1, 5, 7]
Extracting Tuples having K digit elements
We need to find all the tuples from the list whose all elements have exactly k number of digits.
Input:
[(32, 55), (12, 6), (16, 99), (120, 32)]
Output:
[(32, 55), (16, 99)]
Python programming language provides more than one way to perform the task.
Method 1:
A method to solve the problem is using some built-in function in python to select all tuples with k digit values. We will use the filter() method to filter find all the tuples k digit values, for this we will be using the lambda function.
Program:
Output:
Method 2:
We can perform the same task in a better way using list comprehension and all() method.
Program:
Output: