def remove_keyword(modified_keyword):
global plain_alpha
for i in modified_keyword:
if i in plain_alpha:
plain_alpha.replace(i, "")
print(plain_alpha)
return plain_alpha
print(remove_keyword(keyword))
-------------------------------------------------So the request is:
the method return the modified string.
In this example, all the characters in âzebrasâ are removed from the plain alphabet
âabcdefghijklmnopqrstuvwxyzâ to produce âcdfghijklmnopqtuvwxyâ.
4 Réponses :
Vous pouvez essayer ceci pour obtenir la sortie souhaitée.
>>>a='zebra'
>>>b='abcdefghijklmnopqrstuvwxyz'
>>> for i in a:
b=b.replace(i,'')
>>> b
'cdfghijklmnopqtuvwxy'
changez ceci et il devrait fonctionner
plain_alpha = plain_alpha.replace(i, "")
Les méthodes de chaîne ne modifient pas les chaînes en place, car les chaînes sont immuables. Cela signifie appeler remplacer code> ne modifie pas plain_alpha code> de quelque manière que ce soit; Une nouvelle chaîne est retournée à la place. Changer plain_alpha = plain_alpha.replace(i, "")
String dans Python est immuable, remplacez-la donc ne changera pas le contenu de la chaîne mais retournera une nouvelle chaîne. P>
Qu'est-ce qui ne fonctionne pas?