从usin python中的数组中删除重复数据 [英] Remove duplicate data from an array in usin python

查看:65
本文介绍了从usin python中的数组中删除重复数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据数组,我注意到每个数据两次。有什么方法可以删除重复数据以简化数组内容?以下是我在python中制作的代码:

I have an array with data and I notice that I have each data twice. Is there any method to remove the duplicate data to simplify the array content? Below is the code that I made in 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)


推荐答案

我希望您的匹配项是列表。然后您可以使用简单的方法。

I hope your matches is a list.Then you can use simple method.

In [1]: a = [1,1,2,2,3,3,4,4,5]
In [2]: list(set(a))
Out[2]: [1, 2, 3, 4, 5]

仅对您的代码进行一次修改。

For your code only one modification.

matches = list(set(re.findall(r"http://motor\.as\.com/motor/\d+/\d+/\d+/motociclismo/\d+_\d+.html", html)))

这篇关于从usin python中的数组中删除重复数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆