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]
That is all the basic information required here. Now, let's get back to the problem and see the sample inputs and their outputs for a better understanding of the problem.
Input:
myTup = (5, 1, 8, 3, 9) myList = [2, 4, 7, 8, 0]
Output:
true
Now, let's see methods to solve the problem. To do this, we need to check if there is any element that is present in both the arrays.
For this, we will traverse both and find any common element, if present and return a boolean value based on it.
Python programming language allows us to solve this problem in multiple ways and also some built-in methods from the python library can be helpful in performing the task.
Method 1:
A method that can be used to solve the problem is by traversing all the structures and checking if there exists one element which is present in both and returns a boolean value based on it.
Program to check if any list element is present in Tuple
Output:
Method 2:
Another method that can be utilized to check if any element is present in the tuple is by using any() method along with comprehension. This will return true if any element is common in both else return false.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer