def gamma(ranks_list1,ranks_list2):
    '''
    Goodman and Kruskal's gamma correlation coefficient
    :param ranks_list1: a list of ranks (integers)
    :param ranks_list2: a second list of ranks (integers) of equal length with corresponding entries
    :return: Gamma correlation coefficient (rank correlation ignoring ties)
    '''
    num_concordant_pairs = 0
    num_discordant_pairs = 0
    num_tied_x = 0
    num_tied_y = 0
    num_tied_xy = 0
    num_items = len(ranks_list1)
    for i in range(num_items):
        rank_1 = ranks_list1[i]
        rank_2 = ranks_list2[i]
        for j in range(i + 1, num_items):
            diff1 = ranks_list1[j] - rank_1
            diff2 = ranks_list2[j] - rank_2
            if (diff1 > 0 and diff2 > 0) or (diff1 < 0 and diff2 < 0):
                num_concordant_pairs += 1
            elif (diff1 > 0 and diff2 < 0) or (diff1 < 0 and diff2 > 0):
                num_discordant_pairs += 1
            elif diff1 == 0 and diff2 == 0:
                num_tied_xy += 1
            elif diff1 == 0:
                num_tied_x += 1
            elif diff2 == 0:
                num_tied_y += 1
    try:
        gamma_corr_coeff = float(num_concordant_pairs - num_discordant_pairs)/float(num_concordant_pairs + num_discordant_pairs)
    except:
        gamma_corr_coeff = 'n/a'
    return [num_tied_x, num_tied_y, num_tied_xy, gamma_corr_coeff]
Goodman and Kruskal's gamma correlation coefficient
    :param ranks_list1: a list of ranks (integers)
    :param ranks_list2: a second list of ranks (integers) of equal length with corresponding entries
    :return: Gamma correlation coefficient (rank correlation ignoring ties)