"""Return a copy of str1 with characters from str2 removed.
filter_string(string, string) -> string
"""
for a in str1:
if a in str2:
str1.replace(a,"")
return str1
Run Code Online (Sandbox Code Playgroud)
我接近了吗?
str1和str2包含变量字符串
到目前为止,我的输出是21 oramrfrrdonRsmsov creea h tite twrch
期望的输出是21mdnRmvhiwh
def save_friend(filename, friends_list):
rows = ''
strings = open(filename, 'Ur')
for c in strings:
rows += ','.join(c)
rows += '\n'
return strings.write(rows)
Run Code Online (Sandbox Code Playgroud)
尝试将列表覆盖(friends_list)到文件(filename).测试时不断收到此错误消息IOError: File not open for writing.但我以前的功能打开文件就好了..