Sock Merchant
Function Description
Complete the sockMerchant function in the editor below. It must return an integer representing the number of matching pairs of socks that are available.
sockMerchant has the following parameter(s):
- n: the number of socks in the pile
- ar: the colors of each sock
Input Format
The first line contains an integer n , the number of socks represented in ar. The second line contains n space-separated integers describing the colors ar[i] of the socks in the pile.
Constraints
Output Format
Return the total number of matching pairs of socks that John can sell.
Sample Input
910 20 20 10 10 30 50 10 20
Sample Output
3
Explanation
John can match three pairs of socks.
from collections import Counter# Complete the sockMerchant function below.def sockMerchant(n, ar): sum = 0 for values in Counter(ar).values(): sum += values // 2 return sumif __name__ == '__main__': n = int(input()) ar = list(map(int, input().rstrip().split())) result = sockMerchant(n, ar) print(result)