input = open("./test.txt", "r") for line in input: lastFourChar = [] position = 0 for char in line: position += 1 lastFourChar.append(char) if (len(lastFourChar) > 3): # figure out comparison logic here print(lastFourChar) if (len(lastFourChar) == 4): lastFourChar.pop(0)