def ensure_equal_len(iterable, msg=''):
    """ Ensures that all members of an iterable have the same length.
    Raises ValueError if not, using the passed msg. Returns the length.
    """
    bulk_len = None
    for item in iterable:
        if len(item) != bulk_len:
            if bulk_len is None:
                bulk_len = len(item)
            else:
                raise ValueError(msg)
    return bulk_len
