You are given two lists of different lengths of positive integers. Write an algorithm to count the number of elements that are not common to each list.
Input
The first line of the input consists of an integer – listInput1_size, an integer representing the number of elements in the first list (N).
The second line consists of N space-separated integers representing the first list of positive integers.
The third line consists of an integer- listInput2_size, representing the number of elements in the second list (M).
The last line consists of M space-separated integers representing the second list of positive integers.
Output
Print a positive integer representing the count of elements that are not common to both the lists of integers.
Example
Input:
11
1 1 2 3 4 5 5 7 6 9 10
10
11 12 13 4 5 6 7 18 19 20
Output:
12
Explanation:
The numbers that are not common to both lists are [1, 1, 2, 3, 9, 10, 11, 12, 13, 18, 19, 20].
So, the output is 12.
Solution
"""
listInput1, representing the array with size of listInput1_size.
listInput2, representing the array with size of listInput2_size.
"""
def countOfElement(listInput1, listInput2):
# Write your code here
count = 0
for i in listInput1:
if i not in listInput2:
count += 1
for i in listInput2:
if i not in listInput1:
count += 1
return count
def main():
#input for listInput1
listInput1 = []
listInput1_size = int(input())
…
if __name__ == "__main__":
main()
Happy Learning – If you require any further information, feel free to contact me.