def _prepare_community_comparison(comm1, comm2, remove_none=False):
    'Auxiliary method that takes two community structures either as\n    membership lists or instances of L{Clustering}, and returns a\n    tuple whose two elements are membership lists.\n\n    This is used by L{compare_communities} and L{split_join_distance}.\n\n    @param comm1: the first community structure as a membership list or\n      as a L{Clustering} object.\n    @param comm2: the second community structure as a membership list or\n      as a L{Clustering} object.\n    @param remove_none: whether to remove C{None} entries from the membership\n      lists. If C{remove_none} is C{False}, a C{None} entry in either C{comm1}\n      or C{comm2} will result in an exception. If C{remove_none} is C{True},\n      C{None} values are filtered away and only the remaining lists are\n      compared.\n    '

    def _ensure_list(obj):
        if isinstance(obj, Clustering):
            return obj.membership
        return list(obj)
    (vec1, vec2) = (_ensure_list(comm1), _ensure_list(comm2))
    if (len(vec1) != len(vec2)):
        raise ValueError('the two membership vectors must be equal in length')
    if (remove_none and ((None in vec1) or (None in vec2))):
        idxs_to_remove = [i for i in xrange(len(vec1)) if ((vec1[i] is None) or (vec2[i] is None))]
        idxs_to_remove.reverse()
        n = len(vec1)
        for i in idxs_to_remove:
            n -= 1
            (vec1[i], vec1[n]) = (vec1[n], vec1[i])
            (vec2[i], vec2[n]) = (vec2[n], vec2[i])
        del vec1[n:]
        del vec2[n:]
    return (vec1, vec2)
Auxiliary method that takes two community structures either as
membership lists or instances of L{Clustering}, and returns a
tuple whose two elements are membership lists.

This is used by L{compare_communities} and L{split_join_distance}.

@param comm1: the first community structure as a membership list or
  as a L{Clustering} object.
@param comm2: the second community structure as a membership list or
  as a L{Clustering} object.
@param remove_none: whether to remove C{None} entries from the membership
  lists. If C{remove_none} is C{False}, a C{None} entry in either C{comm1}
  or C{comm2} will result in an exception. If C{remove_none} is C{True},
  C{None} values are filtered away and only the remaining lists are
  compared.
def _prepare_community_comparison(comm1, comm2, remove_none=False):
    'Auxiliary method that takes two community structures either as\n    membership lists or instances of L{Clustering}, and returns a\n    tuple whose two elements are membership lists.\n\n    This is used by L{compare_communities} and L{split_join_distance}.\n\n    @param comm1: the first community structure as a membership list or\n      as a L{Clustering} object.\n    @param comm2: the second community structure as a membership list or\n      as a L{Clustering} object.\n    @param remove_none: whether to remove C{None} entries from the membership\n      lists. If C{remove_none} is C{False}, a C{None} entry in either C{comm1}\n      or C{comm2} will result in an exception. If C{remove_none} is C{True},\n      C{None} values are filtered away and only the remaining lists are\n      compared.\n    '

    def _ensure_list(obj):
        if isinstance(obj, Clustering):
            return obj.membership
        return list(obj)
    (vec1, vec2) = (_ensure_list(comm1), _ensure_list(comm2))
    if (len(vec1) != len(vec2)):
        raise ValueError('the two membership vectors must be equal in length')
    if (remove_none and ((None in vec1) or (None in vec2))):
        idxs_to_remove = [i for i in xrange(len(vec1)) if ((vec1[i] is None) or (vec2[i] is None))]
        idxs_to_remove.reverse()
        n = len(vec1)
        for i in idxs_to_remove:
            n -= 1
            (vec1[i], vec1[n]) = (vec1[n], vec1[i])
            (vec2[i], vec2[n]) = (vec2[n], vec2[i])
        del vec1[n:]
        del vec2[n:]
    return (vec1, vec2)