I should replace the last element of a tuple in a list of tuples with and object given as input and I tried to write this code but I got a "list assignment index out of range" error at line 4. How should I fix it?
def replaceLast (tupleList, object):
for i, tup in enumerate(tupleList):
lis = list(tup)
lis[-1] = object
tupleList[i] = tuple(lis)
return tupleList
lT=[(1,),(2,3),(),(7,3)]
replaceLast(lT,11) #=> [(11,), (2, 11), (11,), (7, 11)] -> this should be the result