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']
是否有一个
使用这些结果的方法。
['<html>','<head>']
推荐答案
d = ">"
for line in all_lines:
s = [e+d for e in line.split(d) if e]
这篇关于Python split()而不删除定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文