I'm trying to code this Bigram, I've this code but it keeps given me:
counts[given][char] += 1
IndexError: list index out of range
I don't know how to handle it. Can anyone help me?
def pairwise(s):
a,b = itertools.tee(s)
next(b)
return zip(a,b)
counts = [[0 for _ in range(52)] for _ in range(52)]
with open('path/to/open') as file:
for a,b in pairwise(char for line in file for word in line.split() for char in word):
given = ord(a) - ord('a')
char = ord(b) - ord('a')
counts[given][char] += 1
I get this error:
Traceback: counts[given][char] += 1 IndexError: list index out of range