import math before = []#[0,1,2,3] after = ["a","b","c","d"] both = before + after scroll = -3 lines = 1 start = len(before) + scroll if start+lines < len(both): result = both[start:start+lines] else: result = both[-lines:] print("%s" % result)