【发布时间】:2019-04-21 05:51:17
【问题描述】:
我的问题是我想写一个这样的代码:
input => str_of_words = '<post>30blueyellow<post>2skyearth<post>5summerwinter'
output => post30 = ["blue","yellow"]
post2 = ["sky","earth"]
post5 = ["summer", "winter"]
起初我以为我可以做类似的事情
if "<post>" in str_of_words:
occurrence = str_of_words.count("<post>")
#and from there I had no idea how to continue coding it
所以我觉得我可以问是否有人知道一些技巧来做到这一点
【问题讨论】:
-
Python 中提供了很多字符串技巧,但是通过分隔符
<post>(我们使用str.split("<post>")来分割字符串)和试图找出两个词是什么之间存在很大差异在30blueyellow中,没有可辨别的规则来分割它们。
标签: string python-3.x list spyder