版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1. 输出算法的运行时长
import time
start_time = time.time()
// 算法处理
end_time = time.time()
print("运行时长:",(end_time-start_time),"s")
2. python切割字符串
txt = "Google#Taobao#Facebook"
x = txt.split("#")
print(x)
// ['Google', 'Taobao', 'Facebook']
x = txt.split("#",1)
print(x)
// ['Google', 'Taobao#Facebook']
3. 获取某字符串中括号内的内容
import re
want_str = re.findall(r'[\[](.*?)[\]]', whole_str)
4. 获取某字符串小括号内的内容
import re
want_str = re.findall(r'[(](.*?)[)]', whole_str)