with open('input6.txt','r') as f: inp = f.read().splitlines(keepends=False) inp = inp[0] for i in range(3, len(inp)): tempa = inp[i - 3:i+1] tempc = 0 for x in tempa: tempc += tempa.count(x) if tempc == 4: paketstart = i + 1 break print('Start of packet', paketstart) for i in range(13, len(inp)): tempa = inp[i - 13:i+1] tempc = 0 for x in tempa: tempc += tempa.count(x) if tempc == 14: messagestart = i + 1 break print('Start of Message', messagestart)