My code returns
IndexError: string index out of range
The code is supposed to make a string be split into groups of two and inserted into a list but instead returns Error
def tokenize(tokenlist):
newList = []
for i in range(1,6,2):
newList.append(tokenlist[i]+tokenlist[i+1])
return newList
The input is "abcdef" and the
output I expected was the list ["ab","cd","ef"] but I got an error. How do I get my code to do what I intended?
tokenlist[i] + tokenlist[i+1]is the same astokenlist[i:i+2]