An algorithm problem in python

domain_name = ["sohu", "sina", "baidu", "lagou", "qichacha", "tianyancha", "qq.com", "163.com", "juzi.com",
                            "36kr", "cyzone", "qixin", "kanzhun", "liepin", "zhihu", "weibo", "apple", "zhaopin",
                            "baike"]
def filter_url(url):
    for domain in domain_name:
        if domain in url:
            return
        
if filter_url("xy2.netease.com/thread"):
    print("xy2.netease.com/thread")
    
domain_nameurl pass  url 
Sep.17,2021

your filter_url returns None , always None
bool (None) = = False
so if can never pass


def filter_url(url):
    for domain in domain_name:
        if domain in url:
            return True

if I understand what you mean correctly:

def filter_url(url):
    for domain in domain_name:
        if domain in url:
            pass
        else:
            print(url)
In the

function, the function ends as soon as return occurs. If return is used, Filter will be terminated once it is judged to be True,.

Menu