def same_rank(hand, n_of_a_kind):
    """
    Given a hand of cards, return the number of
    n_of_a_kind combinations of ranks.
    For example, with n_of_a_kind=2, the function
    returns the number of pairs in the hand.
    """
    ranks = [card[1:] for card in hand]
    counter = 0
    already_counted = []
    for rank in ranks:
        if rank not in already_counted and \
                ranks.count(rank) == n_of_a_kind:
            counter += 1
            already_counted.append(rank)
    return counter