Reputation:
I have created a function that returns the following error:
original_alphabet.remove(value)
AttributeError: 'str' object has no attribute 'remove'
I'm not how to fix the error, any help is appreciated. This is my code:
def keyword_cipher_alphabet(keyword):
original_alphabet = "abcdefghijklmnopqrstuvwxyz"
for value in original_alphabet:
if value in keyword:
original_alphabet.remove(value)
keyword_alphabet = ""
for value in original_alphabet:
keyword_alphabet += value
user_keyword = ""
for value in keyword:
user_keyword += value
result = user_keyword + keyword_alphabet
return result.upper()
Upvotes: 1
Views: 19780
Reputation: 2645
The error is caused because strings don't have a method remove
. You might try replace
instead:
$> my_str = 'abc'
$> my_str = my_str.replace('b', '')
$> my_str
'ac'
Upvotes: 2