From 88de7ccff54281c55c5f2d19b825bb02268ee9bf Mon Sep 17 00:00:00 2001 From: souvikghosh05 Date: Wed, 3 Nov 2021 21:42:21 +0530 Subject: [PATCH] Python file for finding number of pairs --- maths/iterative_pair.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 maths/iterative_pair.py diff --git a/maths/iterative_pair.py b/maths/iterative_pair.py new file mode 100644 index 000000000..f113ced55 --- /dev/null +++ b/maths/iterative_pair.py @@ -0,0 +1,44 @@ +import math +import os +import random +import re +import sys +from collections import Counter +import doctest + +# +# Complete the 'sockMerchant' function below. +# +# The function is expected to return an INTEGER. +# The function accepts following parameters: +# 1. INTEGER n +# 2. INTEGER_ARRAY ar +# + + +def sockMerchant(n, ar): + """ + >>> sockMerchant(9, [10, 20, 20, 10, 10, 30, 50, 10, 20]) + 3 + >>> sockMerchant(4, [1, 1, 3, 3]) + 2 + + """ + + i = 0 + occur = Counter(ar) + + for x in occur.values(): + i += x // 2 + return i + + +if __name__ == "__main__": + + n = int(input("Enter length of array:- \n").strip()) + + ar = list(map(int, input("Enter the elements: \n").rstrip().split())) + + result = sockMerchant(n, ar) + print(result) + doctest.testmod()