def degree(data):
    """
    Return the same dataframe containing the degree and multidegree of each
    junction.

    Parameters:
    -----------
    data: pandas dataframe
        data must contain at least one column named neighbors.   

    Returns:
    --------
    data: pandas dataframe
        The input data but with new columns giving the degree and multidegree 
        of each junction.
    """
    
    degreeG = []
    degreeMG = []
    
    for i in range(len(data)):
        A = data.iloc[i][['small_junction','bridge']].to_list()
        if A == [1,0]:
            degreeG += [0]
            degreeMG += [0]
        elif A == [1,1]:
            degreeG += [2]
            degreeMG += [2]
        else:
            L = data.iloc[i]['neighbors_list']
            degG = 0
            degMG = 0
            for neighbor in L:
                if data.iloc[neighbor][['small_junction','bridge']].to_list() == [1,0]:
                    degG += 0
                    degMG += 0
                elif data.iloc[neighbor][['small_junction','bridge']].to_list() == [1,1]:
                    degG += 1
                    degMG += 1
                else:
                    degG += 1
                    M = data.iloc[i]['neighbors']
                    n = len(M)
                    j = 0
                    t = False
                    while ((j < n) and not t):
                        if M[j][0] == neighbor:
                            degMG += M[j][2]
                            t = True
                        else:
                            j += 1
            degreeG += [degG]
            degreeMG += [degMG]
    
    data['degreeG'] = degreeG
    data['degreeMG'] = degreeMG
    
    return data