小编Sun*_*eTS的帖子

过滤字符串中的字符

我需要创建一个函数,它接受两个字符串作为imnput,并返回str 1的副本,删除str2中的所有字符.

首先是使用for循环遍历str1,然后与str2进行比较,以完成减法我应该创建第3个字符串来存储输出,但之后我有点失落.

def filter_string(str1, str2):
    str3 = str1   
    for character in str1:
       if character in str2:
           str3 = str1 - str2
    return str3
Run Code Online (Sandbox Code Playgroud)

这就是我一直在玩的但我不明白我该怎么做.

python string iteration

6
推荐指数
2
解决办法
4万
查看次数

迭代字典

我试图返回字典中值大于int argurment的所有值.

def big_keys(dict, int):
    count = []
    for u in dict:
        if u > int:
            count.append(u)
    return count
Run Code Online (Sandbox Code Playgroud)

我不明白为什么这不起作用.它返回列表中的每个值,而不仅仅是那些大于in的值.

python dictionary loops

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

标签 统计

python ×2

dictionary ×1

iteration ×1

loops ×1

string ×1