我想删除字符串中的所有URL(用""替换它们)我搜索过但却找不到我想要的东西.
例:
text1
text2
http://url.com/bla1/blah1/
text3
text4
http://url.com/bla2/blah2/
text5
text6
http://url.com/bla3/blah3/
Run Code Online (Sandbox Code Playgroud)
我希望结果如下:
text1
text2
text3
text4
text5
text6
Run Code Online (Sandbox Code Playgroud) 检查字符串是否包含列表中任何项目的某些字符的最快方法是什么?
目前,我正在使用这种方法:
lestring = "Text123"
lelist = ["Text", "foo", "bar"]
for x in lelist:
if lestring.count(x):
print 'Yep. "%s" contains characters from "%s" item.' % (lestring, x)
Run Code Online (Sandbox Code Playgroud)
有没有办法在没有迭代的情况下做到这一点(我认为这会让它更快.)?
第一种方法:
import threading
import time
def keepalive():
while True:
print 'Alive.'
time.sleep(200)
threading.Thread(target=keepalive).start()
Run Code Online (Sandbox Code Playgroud)
第二种方法:
import threading
def keepalive():
print 'Alive.'
threading.Timer(200, keepalive).start()
threading.Timer(200, keepalive).start()
Run Code Online (Sandbox Code Playgroud)
哪种方法占用更多内存?在第二种方法中,线程在被激活后结束了吗?或者它是否保留在内存中并启动新线程?(多线程)
python ×3
python-2.7 ×2
iteration ×1
list ×1
memory ×1
performance ×1
regex ×1
replace ×1
timer ×1
url ×1