This what I have so far. It’s for homework. We can’t use slices. I can’t seem to figure it out.
def insert(s1, s2, pos):
s3 = list(s1)
for i,s in enumerate(s3):
if i == pos:
s3[pos + 1] = s
s3[i] = s2
"".join(s3)
return s3
With the above, the last character of string s1 gets deleted and the join method is not joining s3 into a single string.
Notice the lines
If you look at the join documentation, you’ll see that join doesn’t modify its argument, but instead generates a string containing the contents of the argument list, all joined together. So you’re throwing away the result of
and returning
s3(a list) instead. So, you need to change the last two lines toSince this is homework, I won’t comment on the rest of the code, but returning the result of the join call will certainly help.