扫描滑动窗口,查找字符串中字母的某些组合。计算出现次数。 Python
如果您有一个序列并创建了一个窗口大小为 4 的列表。在每个窗口中您都在寻找特定的排列。
#Example:
count=0
test='abcdaecdagcd'
windows=['abcd','bcda','cdae','daec','aecd','ecda','cdag','dagc','agcd']
我正在寻找序列中 a-[b 或 e]-*-d 的特定主题,我想计算它出现的次数,
因此 'abcd' 和 'aecd' 可以工作,因为 'a-[b或 e]-(这个位置无关紧要)-d' 这将添加到计数 2,因此在函数执行之后,计数 = 2
If you have a sequence and you create a a list of window size 4. In each of those windows your looking for particular arrangement.
#Example:
count=0
test='abcdaecdagcd'
windows=['abcd','bcda','cdae','daec','aecd','ecda','cdag','dagc','agcd']
I'm looking for a particular motif which is a-[b or e]-*-d within the sequence and I want to count how many times it occurs
so 'abcd' and 'aecd' would work because 'a-[b or e]-(this position doesn't matter)-d' which would add to the count 2 so after the function went through it would be count = 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串“a(b or e)*d”不能以字符串“a(b or e)*d”开头。因此,长字符串中存在的此类字符串不能重叠,然后可以使用正则表达式来查找您需要的
内容:
A string 'a(b or e)*d' can't begin in a string 'a(b or e)*d'. Hence strings of this kind present in a long string can't overlap, and then a regex is usable to find what you need:
result