def consolidate(arr):
    """Merges intersecting sets in a list of sets.

    Taken from: http://rosettacode.org/wiki/Set_consolidation#Python:_Iterative

    Recursive version will hit max recursion depth.
    """
    sets = [s for s in arr if s]
    for i, s1 in enumerate(sets):
        if s1:
            for s2 in sets[i+1:]:
                if s1.intersection(s2):
                    s2.update(s1)
                    s1.clear()
                    s1 = s2
    return [s for s in sets if s]