(seq1: Iterable[str], seq2: Iterable[str])
Measure the similarity between two sequences of strings (*not* as sets)
    using the "bag distance" measure, which can be considered an approximation
    of edit distance.

    Args:
        seq1
        seq2

    Returns:
        Similarity between ``seq1`` and ``seq2`` in the interval [0.0, 1.0],
        where larger values correspond to more similar sequences

    Reference:
        Bartolini, Ilaria, Paolo Ciaccia, and Marco Patella. "String matching with
        metric trees using an approximate distance." International Symposium on String
        Processing and Information Retrieval. Springer, Berlin, Heidelberg, 2002.
Measure the similarity between two sequences of strings (*not* as sets)
    using the "bag distance" measure, which can be considered an approximation
    of edit distance.
Measure the similarity between two sequences of strings ( * not * as sets ) using the bag distance measure which can be considered an approximation of edit distance .
def bag(seq1: Iterable[str], seq2: Iterable[str]) -> float:
    """
    Measure the similarity between two sequences of strings (*not* as sets)
    using the "bag distance" measure, which can be considered an approximation
    of edit distance.

    Args:
        seq1
        seq2

    Returns:
        Similarity between ``seq1`` and ``seq2`` in the interval [0.0, 1.0],
        where larger values correspond to more similar sequences

    Reference:
        Bartolini, Ilaria, Paolo Ciaccia, and Marco Patella. "String matching with
        metric trees using an approximate distance." International Symposium on String
        Processing and Information Retrieval. Springer, Berlin, Heidelberg, 2002.
    """
    bag1 = collections.Counter(seq1)
    bag2 = collections.Counter(seq2)
    max_diff = max(sum((bag1 - bag2).values()), sum((bag2 - bag1).values()))
    max_len = max(sum(bag1.values()), sum(bag2.values()))
    try:
        return 1.0 - (max_diff / max_len)
    except ZeroDivisionError:
        return 0.0
def bag ( seq1 : Iterable [ str ] , seq2 : Iterable [ str ] ) -> float : bag1 = collections . Counter ( seq1 ) bag2 = collections . Counter ( seq2 ) max_diff = max ( sum ( ( bag1 - bag2 ) . values ( ) ) , sum ( ( bag2 - bag1 ) . values ( ) ) ) max_len = max ( sum ( bag1 . values ( ) ) , sum ( bag2 . values ( ) ) ) try : return 1.0 - ( max_diff / max_len ) except ZeroDivisionError : return 0.0