This should be possible in O(n) time complexity and O(n) space in the event that you utilize a hashtable.
Hashtable would have Key = shade(color) of Socks, Value = absolute check of each tone.
total_count = dict()
for i in range(len(arr)):
if arr[i] in total_count:
total_count[arr[i]] += 1
pairs = 0
for i in total_count:
pairs += int(total_count[i] / 2)
print(pairs)
Emphasize (Iterate) once over the array and store every event of color in a hashtable. At that point repeat over the hashtable to check if count of each tone are separable by 2. That would give you your sets.
Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.