def test_same_type(iterable_obj):
    """
    Utility function to test whether all elements of an iterable_obj are of the 
    same type. If not it raises a TypeError.
    """
    # by set definition, the set of types of the elements in iterable_obj
    # includes all and only the different types of the elements in iterable_obj.
    # If its length is 1, then all the elements of iterable_obj are of the 
    # same data-type
    if len(set([type(x) for x in iterable_obj])) == 1:
        # all element are of the same type: test successful!
        return True
    else:
        raise TypeError("Iterable '{}' in input has elements of heterogeneous types: {}"
                        .format(iterable_obj, [type(x) for x in iterable_obj]))