def truncate(s, max_len=<NUM_LIT:20>, ellipsis='<STR_LIT>'):
if s is None:<EOL><INDENT>return None<EOL><DEDENT>elif isinstance(s, basestring):<EOL><INDENT>return s[:min(len(s), max_len)] + ellipsis if len(s) > max_len else '<STR_LIT>'<EOL><DEDENT>elif isinstance(s, Mapping):<EOL><INDENT>truncated_str = str(dict(islice(viewitems(s), max_len)))<EOL><DEDENT>else:<EOL><INDENT>truncated_str = str(list(islice(s, max_len)))<EOL><DEDENT>return truncated_str[:-<NUM_LIT:1>] + '<STR_LIT>' if len(s) > max_len else truncated_str<EOL>
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...'