[Solved] python grammar mistake invalid syntax


One problem with your code is that the index n1 by definition does not exist in your list. Python lists indices start at 0, so a list with length 3 only has indices 0-2.

mylist = ["a", "b", "c"]
print(len(mylist))
# 3
print(mylist[3])
# IndexError!
print(mylist[2])
# "c"

Instead of this:

n1 = len(p1)

Try this:

n1 = len(p1) - 1

2

solved python grammar mistake invalid syntax