BEstyle 2022. 10. 29. 02:13

DESCRIPTION:

Pair of gloves

Winter is coming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer.

Given an array describing the color of each glove, return the number of pairs you can constitute, assuming that only gloves of the same color can form pairs.

Examples:

input = ["red", "green", "red", "blue", "blue"]
result = 2 (1 red pair + 1 blue pair)

input = ["red", "red", "red", "red", "red", "red"]
result = 3 (3 red pairs)

def number_of_pairs(gloves):
    count=0
    for i in range(len(gloves)-1):
        for j in range(i+1,len(gloves)):
            if gloves[i]==gloves[j] and gloves[i]!="":
                gloves[i]=""
                gloves[j]=""
                count+=1
    return count