** Examples :**

Input:tuple = (`a`,` a`, `c`,` b`, `d` ) list = [`a`,` b`]Output:3Input:tuple = (1, 2, 3, 1, 4, 6, 7, 1, 4) list = [1, 4, 7]Output:6

** Approach # 1: ** Naive Approach

First Approach — naive approach. Use a for loop and traverse the given list and count the occurrences of each element of the tuple in the list. Finally, return the score.

```
``` |

** Exit :**

3

** Approach # 2 ** Using a counter

From in the Python Collections module, import the counter to solve this problem. Counter — it is a container that keeps track of how many times equivalent values are added. After storing the result in & # 39; counts & # 39;, we use a for loop and count how many times each item in the list occurs in & # 39; counts & # 39; and sum it up to get the final result.

` `

```
```
` # Python3 Case Counting Program `

` # of all list items in a tuple `

` from `

` collections `

` import `

` Counter `

` def `

` countOccurrence (tup, lst): `

` `

` counts `

` = `

` Counter (tup) `

` return `

` sum `

` (counts [i] `

` for `

` i `` in `

` lst) `

```
```

` Driver code `

` tup `

` = `

` (`

` `a` `

`, `

`` a ``

`, `

`` c` `

`, `

` `b` `

`, `

`` d` `

`) `

` lst `

` = `

` [`

` `a` `

`, `

`` b` `

`] `

` print `

` (countOccurrence (tup, lst)) `

` `

** Exit:**

3

** Approach # 3. ** Using Set

Another method to solve this problem — using the given data structure. Just convert the given list into a set that removes all duplicates. Now, for each element of the list, count its occurrence in a tuple and sum them.

```
``` |

** Exit :**

3

** Approach # 4 ** Used Python dictionary definition

Get each tuple element and its frequency as a key: value pair in the Python dictionary, then using a for loop, for each list element, count its occurrences in the tuple and sum them.

` `

```
```
` # Python3 Case Counting Program `

` # of all list items in a tuple `

` def `

` countOccurrence (tup, lst): `

` dct `

` = `

` {} `

` for `

` i `

` in `

` tup: `

` `

` if `` not `

` dct.get (i): `

```
``` ` dct [i] `

` = `

` 0 `

` dct [i] `

` + `

` = `

` 1 `

` `

` return `

` sum `

` (dct.get (i, `

` 0 `

`) `

` for `

` i `

` in `` lst) `

```
```

` Driver code `

` tup `

` = `

` (`

` `a` `

`, `

`` a` `

`, `

` `c` `

`, `

`` b` `

`, `

` `d` `

`) `

```
``` ` lst `

` = `

` [`

` `a` `

`, `

`` b` `

`] `

` print `

` (countOccurrence (tup, lst)) `

` `

** Exit :**

3

** Approach # 5 : ** Python ` numpy.in1d () `

Python numpy gives us a direct method to find a solution to a given problem, and this is ` numpy.in1d () `

. This method checks if each element of the one-dimensional array is present in the second array. Since the list is also a one-dimensional array, this method can be applied here.

```
``` |

** Exit:**

3

X
# Submit new EBook