Python 字符串替换特定位置字符出错

编写猜单词游戏 比如谜底(puzzle)是banana, 则给出画面(view) ^^^^^^ 每个^指代一个字母 如果玩家输入字母a, 因为banana第2 4 6位置为a, 则对应的view变成 ^a^a^a,
为什么按照下面给的程序 验证时出错 type error: 'int' object is not subscriptable 应该怎么改啊
HIDDEN = '^'
def update_view(puzzle, view, letter):
''' (str, str, str) -> str
Return the view of the puzzle with each occurrence of the letter in the puzzle revealed.
>>> update_view('banana', '^^^^^^', a)
>>> '^a^a^a'
'''
# function body
length = len(puzzle)
for index in range(length):
if length[index] == letter:
view[index] = letter
return view
将line11 改为if puzzle[index]==letter后还是不对
def update_view(puzzle, letter,ma='隐改^' ):
'''ma是掩码,指携仔单个字符^
'''
length = len(puzzle)
lst = []
  for index in range(length):
 唯汪  if puzzle[index] == letter:
   lst[index] = letter
else:

lst[list]=ma

return ''.join(lst)
length = len(puzzle)
lst = [i for i in view]
for index in range(length):
if puzzle[index] == letter:
lst[index] = letter
view = ''.join(lst)
return view

string 的值无法修汪肆改激陵厅,明隐list 可以
if length[index] == letter

改为:茄念嫌
if puzzle[index] == letter

粗颤手心高槐了吧?