小编Jos*_*123的帖子

Python - 返回一个字符串的函数,该字符串将删除另一个字符串中的字符

"""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

python string replace

2
推荐指数
1
解决办法
329
查看次数

python写错误

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.但我以前的功能打开文件就好了..

python for-loop join overwrite

1
推荐指数
1
解决办法
325
查看次数

标签 统计

python ×2

for-loop ×1

join ×1

overwrite ×1

replace ×1

string ×1