Python遍历字符 [英] Python Iterate through characters

查看:76
本文介绍了Python遍历字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试对ACGT基因组中的序列进行中位字符串搜索.我要说的是AAAAAAAA到AAAAAAAC的问题,依此类推,直到我尝试了所有可能的组合.

I have been trying to pull of median string search for a sequence in the ACGT genome. The problem I have is going to say AAAAAAAA to AAAAAAAC and so forth until I have tried every possible combination.

通过创建两个列表,一个包含A,C,G,T,另一个包含8个字符序列,并在每次搜索后迭代和交换字符,我从本质上一直在蛮力地对待它.问题是我没有测试所有组合,因为当两个同时迭代时,它会跳一个字母.

I've been essentially going brute force at it by creating two lists, one containg A,C,G,T and the other the 8 character sequence, and after each search iterating and swapping characters. The problem is that I don't test all combinations because when two iterate at the same time it jumps a letter.

有什么办法可以轻松实现AAAAAAAA-AAAAAAAC-AAAAAAAG-AAAAAAAT-AAAAAACA等吗?

Is there any way to go AAAAAAAA - AAAAAAAC - AAAAAAAG - AAAAAAAT - AAAAAACA and so forth easily?

推荐答案

使用 itertools

itertools.product("ACGT", repeat=8)

这篇关于Python遍历字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆