Solution for String index out of range even though I’ve circumvented it in my code
is Given Below:
I’m creating a function which returns a list of elements without any elements of the same value next to each other. However, I experience this error even though I don’t see how it could happen?
if s[i + 1] != s[i] or s[i - 1] != s[i]: IndexError: string index out of range
My program is as follows:
def unique_in_order(s): arr =  for i in range(0, len(s)): if i == 0 or i == len(s): arr.append(s[i]) else: if s[i + 1] == s[i] or s[i - 1] == s[i]: pass else: arr.append(s[i]) return arr