0 out of 464 challenges solved
Write a Python function `count_occurrences(tup, lst)` that takes a tuple `tup` and a list `lst` as input and returns the total count of elements in `tup` that are present in `lst`. #### Example Usage ```python [main.nopy] # Example 1 tup = ('a', 'a', 'c', 'b', 'd') lst = ['a', 'b'] print(count_occurrences(tup, lst)) # Output: 3 # Example 2 tup = (1, 2, 3, 1, 4, 6, 7, 1, 4) lst = [1, 4, 7] print(count_occurrences(tup, lst)) # Output: 6 # Example 3 tup = (1, 2, 3, 4, 5, 6) lst = [1, 2] print(count_occurrences(tup, lst)) # Output: 2 ```
def count_occurrences(tup, lst): """ Count the occurrences of elements from the list in the tuple. Parameters: tup (tuple): The tuple to search within. lst (list): The list of elements to count in the tuple. Returns: int: The total count of elements from the list found in the tuple. """ # Initialize a counter count = 0 # Iterate through the tuple and count occurrences of elements in the list # Placeholder for implementation return count