-4
foo = ("PandaBears")
l = list(foo)
random.shuffle(l)
Output = ''.join(l)
print(Output)
我一直在這個代碼試圖找出問題的年齡,但我沒有運氣。幾個小時它完全沒有麻煩完美的工作之前 - I haven't even changed/upgraded python either.
TypeError:列表標記必須是整數,而不是str
錯誤就要從
l = list(idf)
和我一直在使用[]
代替()
試過。
在這段代碼的任何改進,將不勝感激
該代碼表示l = list(foo)。但我看到l = list(idf)。什麼是idf? –
你正試圖洗牌字符串的字符? –
發佈的代碼正確地洗牌字符串的字符。請確保您確認代碼重現錯誤。 –