をサポートしていない私は暗号ソルバーを作るために他の誰かのコードを使用していますが、それはあり不変の文字列、TypeError例外:「strの」オブジェクトは、アイテムの割り当て
key[keyIndex] = cipherletter
でくれ
typeerror: 'str' object does not support item assignment"
を与えますエラーと同じ意味を維持する方法? :)
def decryptWithCipherletterMapping(ciphertext, letterMapping):
# Return a string of the ciphertext decrypted with the letter mapping,
# with any ambiguous decrypted letters replaced with an _ underscore.
# First create a simple sub key from the letterMapping mapping.
key = ['x'] * len(LETTERS)
for cipherletter in LETTERS:
if len(letterMapping[cipherletter]) == 1:
# If there's only one letter, add it to the key.
keyIndex = LETTERS.find(letterMapping[cipherletter][0])
key[keyIndex] = cipherletter
else:
ciphertext = ciphertext.replace(cipherletter.lower(), '_')
ciphertext = ciphertext.replace(cipherletter.upper(), '_')
key = ''.join(key)
# With the key we've created, decrypt the ciphertext.
return simpleSubCipher.decryptMessage(key, ciphertext)
Pythonでは、文字列は不変なので、文字をインプレースで変更することはできません。 –