def create_sorted_endpointlist(intervals):
    """ Function: create_sorted_endpointlist()

        Purpose:  Create sorted endpoints list for a set of intervals.
                  If two intervals share the same endpoint where one is
                  a right and one is a left endpoint, scan left endpoint
                  before right endpoint.
                  
        Input:    Set of intervals. 
        
        Return:   Set of intervals sorted by right endpoints.
    """  
    sorted_list= []
  
    for index, interval in enumerate(intervals):
        firstpoint = (interval[0], 'l', float(interval[4]), index + 1)
        sorted_list.append(firstpoint)
        secondpoint = (interval[1], 'r', float(interval[4]), index + 1)
        sorted_list.append(secondpoint)  
  
    sorted_list = sorted(sorted_list)
        
    return sorted_list