def truncate_list(l, limit):
    """
    Replace the middle of the list `l` with '...' if `l` contains more than
    `limit` elements
    """
    length = len(l)
    if length <= limit:
        return l

    n1 = int(limit / 2.0)
    n2 = limit - n1
    return l[:n1] + ["..."] + l[length - n2:]