a = ['http://www.yahoo.com', 'http://www.google.net', 'gorilla', 'house.com', 'i love the net very much']
b = ['com', 'http', 'net']
result = ['http://www.yahoo.com', 'http://www.google.net', 'house.com', 'i love the net very much']
我如何在a中找到b?匹配a中的b中的任何一个。一个很长的句子
我的正则表达式
for element in a:
m = re.match("anything match in b right?")
if m:
print (m.group())
我不太确定在re.match中放什么
a = ['http://www.yahoo.com', 'http://www.google.net', 'gorilla', 'house.com', 'i love the net very much']
b = ['com', 'http', 'net']
print list(set([i for i in a for j in b if j in i]))
编辑:
对于a中的所有b:
a = ['http://www.yahoo.com', 'http://www.google.net', 'gorilla', 'house.com', 'i love the net very much http and com too']
b = ['com', 'http', 'net']
print set(a)-set([i for i in a for j in b if j not in i])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句