简体   繁体   English

如何按行获取列表中str项目的所有组合python

[英]how to get all combinations of str items of a list row-wise python

I have a fasta file as below:我有一个fasta文件如下:

>seq1
AAAAAAAA
>seq2
TTTTTTTT
>seq3
CCCCCCCC
>seq4
GGGGGGGG

I want to get all combinations of the lines (except the ones that start with > sign) .我想获得所有行的组合(except the ones that start with > sign) The desired output should be:所需的 output 应该是:

AAAAAAAA
TTTTTTTT

AAAAAAAA
CCCCCCCC

AAAAAAAA
GGGGGGGG

TTTTTTTT
CCCCCCCC

TTTTTTTT
GGGGGGGG

CCCCCCCC
GGGGGGGG

My piece of code is here but the last step of making combinations is missing:我的一段代码在这里,但缺少组合的最后一步:

from Bio import SeqIO

list1=[]
with open('file1.fa', 'r') as file1:
    for record1 in SeqIO.parse(file1, 'fasta'):
        list1.append(record1.seq)


for i in list1:
    print(i)

Thank you谢谢

try尝试

from itertools import combinations as com

lst = ['A', 'B', 'C', 'D']
combi = list(com(lst, 2))

for entry in combi:
    print(entry[0])
    print(entry[1])
    print()

output output

A
B

A
C

A
D

B
C

B
D

C
D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM