Python split() 不删除分隔符 [英] Python split() without removing the delimiter
本文介绍了Python split() 不删除分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码几乎可以满足我的需要..
This code almost does what I need it to..
for line in all_lines:
s = line.split('>')
除了删除所有的>"分隔符.
Except it removes all the '>' delimiters.
所以,
<html><head>
变成
['<html','<head']
有没有办法使用 split() 方法但保留分隔符,而不是删除它?
Is there a way to use the split() method but keep the delimiter, instead of removing it?
有了这些结果..
['<html>','<head>']
推荐答案
d = ">"
for line in all_lines:
s = [e+d for e in line.split(d) if e]
这篇关于Python split() 不删除分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文