已关闭。此问题需要超过focused。当前不接受答案。
**想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。
14分钟前就关门了。
Improve this question
如何从字符串中拆分和删除重复的模式,例如?
# sample
s1 = '-c /home/test/pipeline/pipelines/myspace4/.cache/sometexthere/more --log /home/test1/pipeline2/pipelines1/myspace1/.cache/sometexthere/more --arg /home/test4/pipeline3/pipelines3/myspace3/.cache/sometexthere/more --newarg etc.'
# expected
expected = '-c sometexthere/more --log sometexthere/more --arg sometexthere/more --newarg etc.'
# attempt only yields last value rather than all
''.join([ s for s in s1.split('/.cache/')[-1] ])
1条答案
按热度按时间vql8enpb1#
首先在空格周围拆分字符串,这样所有相关部分都将在之后拆分:
输出: