马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我的代码是这样的
import re
one = ['a123','b456','c789','d112','e122','f452','a123','r987','f452','b456']
two = ['123','456','789','112','122','452']
three =[]
for i in one:
if re.search(r'(\d+)',i).group() in two:
three.append(i)
print(three)
得出的结果是
['a123', 'b456', 'c789', 'd112', 'e122', 'f452', 'a123', 'f452', 'b456']
如何才能得到这样的结果
['a123', 'b456', 'c789', 'd112', 'e122', 'f452']
谢谢老师们能帮我看看谢谢了
- import re
- one = ['a123','b456','c789','d112','e122','f452','a123','r987','f452','b456']
- two = ['123','456','789','112','122','452']
- three =[]
- for i in one:
- if re.search(r'(\d+)',i).group() in two and i not in three: # 注意这里
- three.append(i)
- print(three)
复制代码
|