这段代码几乎可以满足我的需要..
for line in all_lines:
s = line.split('>')
除了删除所有的“>”分隔符。
所以,
<html><head>
变成
['<html','<head']
有没有办法使用 split() 方法但保留分隔符,而不是删除它?
有了这些结果..
['<html>','<head>']
最佳答案
d = ">"
for line in all_lines:
s = [e+d for e in line.split(d) if e]
关于Python split() 不删除分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7866128/