我有一个列表,如下所示:
a = ['www.hughes-family.org', 'www.bondedsender.com', 'thinkgeek.com', 'www.hughes-family.org', 'www.hughes-family.org', 'lists.sourceforge.net', 'www.hughes-family.org']
如何检查此列表中是否有超过三个相同的网址?我已经尝试过该set()
功能,但只要有重复的 url 就会显示。这是我尝试过的:
if len(set(a)) < len(a):
您可以使用list.count
来获取出现 3 次或更多次的 url 数:
urls = ['www.hughes-family.org', 'www.bondedsender.com', 'thinkgeek.com', 'www.hughes-family.org', 'www.hughes-family.org', 'lists.sourceforge.net', 'www.hughes-family.org']
new_urls = [url for url in urls if urls.count(url) > 1]
if len(new_urls) > 3:
pass #condition met
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句