def shards_trim_top(shards, top):
    assert top > 0

    shard_iter = iter(shards)
    shard_tail = []
    # skip over shards that are completely removed
    for num_rows, cviews in shard_iter:
        if top < num_rows:
            break
        sbody = shard_body(cviews, shard_tail, False)
        shard_tail = shard_body_tail(num_rows, sbody)
        top -= num_rows
    else:
        raise CanvasError("tried to trim shards out of existence")
    
    sbody = shard_body(cviews, shard_tail, False)
    shard_tail = shard_body_tail(num_rows, sbody)
    # trim the top of this shard
    new_sbody = []
    for done_rows, content_iter, cv in sbody:
        new_sbody.append((0, content_iter, 
            cview_trim_top(cv, done_rows+top)))
    sbody = new_sbody
    
    new_shards = [(num_rows-top, 
        [cv for done_rows, content_iter, cv in sbody])]
    
    # write out the rest of the shards
    new_shards.extend(shard_iter)

    return new_shards
Return shards with top rows removed.
dataset/ETHPy150Open AnyMesh/anyMesh-Python/example/urwid/canvas.py/shards_trim_top