我有一个包含数据的数组,我注意到每个数据都有两次。有什么方法可以去除重复数据来简化数组内容吗?下面是我用 python 编写的代码:
import requests
import re
import bs4
r = requests.get("http://as.com/tag/moto_gp/a/")
r.raise_for_status()
html = r.text
matches = re.findall(r"http://motor\.as\.com/motor/\d+/\d+/\d+/motociclismo/\d+_\d+.html", html)
print (matches)
请您参考如下方法:
我希望你的匹配是一个列表。那么你可以使用简单的方法。
In [1]: a = [1,1,2,2,3,3,4,4,5]
In [2]: list(set(a))
Out[2]: [1, 2, 3, 4, 5]
您的代码只需修改一次。
matches = list(set(re.findall(r"http://motor\.as\.com/motor/\d+/\d+/\d+/motociclismo/\d+_\d+.html", html)))
