我试图写一个函数消除,它接受一个字符串和两个可选参数。第一个可选参数(错误的字符)采用字母,第三个参数(区分大小写)采用布尔值。函数应该接受一个字符串s,并删除所有错误字符的实例。如果区分大小写为true,则函数应表现为区分大小写。如果为false,则不需要。这就是我目前所拥有的。在def eliminate(s,bad_characters = [],case_sensitive = True or False):
''' Takes a string s and returns the string with all bad_characters
removed. If case_sensitive is True, then the function will only
remove uppercase letters if there are uppercase letters in
bad_characters.
String --> String'''
while True:
if case_sensitive = False:
for character in s:
if bad_characters == character:
newlist = s.replace(bad_characters,'')
return newlist
break
我很难弄清楚如何使函数删除大写字母,如果需要的话。如果坏的字符是列表、元组或字符串,那么该函数也应该起作用。在