def organize_edges(edges, borders=None, default_border='land'):
    """
    Organize edges in to various collections specified by borders.

    Required Arguments
    ------------------
    * edges          : List of edges of the form

        (node_number, node_number, ... , edge_type)

                       The sorting process requires edge_type to be the last
                       entry in each tuple.

    Optional Arguments
    ------------------
    * borders        : a dictionary correlating border numbers with names. For
                       example,

          borders = {'ocean_in' : 1, 'ocean_out' : 2}

    * default_border : the border to place all other edges in. Defaults to
                      'land'.
    """
    if borders is None:
        borders = dict()
    if default_border in borders:
        raise ValueError("Specific border and default border share same name")

    edge_collections = dict()
    edge_collections[default_border] = set(edges)
    for border, labels in borders.items():
        edge_collections[border] = {t for t in edge_collections[default_border]
                                    if t[-1] in labels}
        edge_collections[default_border] -= edge_collections[border]
    return edge_collections