def truncate(s, max_len=20, ellipsis='...'):
    r"""Return string at most `max_len` characters or sequence elments appended with the `ellipsis` characters

    >>> truncate(OrderedDict(zip(list('ABCDEFGH'), range(8))), 1)
    "{'A': 0..."
    >>> truncate(list(range(5)), 3)
    '[0, 1, 2...'
    >>> truncate(np.arange(5), 3)
    '[0, 1, 2...'
    >>> truncate('Too verbose for its own good.', 11)
    'Too verbose...'
    """
    if s is None:
        return None
    elif isinstance(s, basestring):
        return s[:min(len(s), max_len)] + ellipsis if len(s) > max_len else ''
    elif isinstance(s, Mapping):
        truncated_str = str(dict(islice(viewitems(s), max_len)))
    else:
        truncated_str = str(list(islice(s, max_len)))
    return truncated_str[:-1] + '...' if len(s) > max_len else truncated_str
def truncate ( s , max_len = 20 , ellipsis = '...' ) : if s is None : return None elif isinstance ( s , basestring ) : return s [ : min ( len ( s ) , max_len ) ] + ellipsis if len ( s ) > max_len else '' elif isinstance ( s , Mapping ) : truncated_str = str ( dict ( islice ( viewitems ( s ) , max_len ) ) ) else : truncated_str = str ( list ( islice ( s , max_len ) ) ) return truncated_str [ : - 1 ] + '...' if len ( s ) > max_len else truncated_str
r"""Return string at most `max_len` characters or sequence elments appended with the `ellipsis` characters

    >>> truncate(OrderedDict(zip(list('ABCDEFGH'), range(8))), 1)
    "{'A': 0..."
    >>> truncate(list(range(5)), 3)
    '[0, 1, 2...'
    >>> truncate(np.arange(5), 3)
    '[0, 1, 2...'
    >>> truncate('Too verbose for its own good.', 11)
    'Too verbose...'