我試圖切換列表中的字符與列表中給定位置的其他字符。例如。 ["*","*","*","*","*",.....]
,在[1,3,4,.....]
位置 與給定的字母更改字符,例如X.在列表中切換列表中的不同數字
所以["*","*","*","*","*","*"]
變得["*",X,"*",X,X,"*"]
。
我試過這個:
def test():
letter="a"
secret="*****"
secret2=list(secret)
pos=[1,3]
y = 1
x = pos[y]
flag = 0
while flag < 2:
secret2[x]=letter
flag = (flag + 1)
y = (y+1)
return secret2
但它只返回列表,["*","*","*",A,"*"]
我將如何解決這個問題?它能在課堂上更輕鬆地解決嗎?那樣的話,這個班怎麼樣?
接受一個答案......看到這個http://meta.stackexchange.com/questions/ 5234/how-does-accepting-an-answer-work/5235#5235 –