import six


def truncate_rows(rows, length=30, length_id=10):
    """
    Truncate every string value in a dictionary up to a certain length.
    :param rows: iterable of dictionaries
    :param length: int
    :param length_id: length for dict keys that end with "Id"
    :return:
    """

    def trimto(s, l):
        """
        Trim string to length.
        :param s: string to trim
        :param l: length
        """
        if isinstance(s, six.string_types):
            return s[:l + 1]
        return s

    result = []
    for row in rows:
        if isinstance(row, dict):
            updated = {}
            for k, v in row.items():
                if k.endswith('Id'):
                    updated[k] = trimto(v, length_id)
                else:
                    updated[k] = trimto(v, length)
            result.append(updated)
        elif isinstance(row, six.string_types):
            result.append(trimto(row, length))
        else:
            result.append(row)
    return result