我在下面的列表中存储了以下几对
sample = [[CGCG,ATAT],[CGCG,CATC],[ATAT,TATA]]
每个成对比较只能有两个唯一的字符组合,如果没有,则消除这些成对比较。例如
In sample[1]
C C
G A
C T
G C
查看两个子列表中的相应元素,CC、GA、CT、GC。你知道吗
这里,有两种以上的成对(CC),(GA),(CT)和(GC)。所以这种两两比较是不可能发生的。你知道吗
每次比较只能有两种组合(AA、GG、CC、TT、AT、TA、AC、CA、AG、GA、GC、CG、GT、TG、CT、TC)。。。基本上所有可能的ACGT组合,其中顺序很重要。你知道吗
在上面的例子中,发现了超过2个这样的组合。你知道吗
但是
In sample[0]
C A
G T
C A
G T
只有两种独特的组合:CA和GT
因此,仅存的一对是:
output = [[CGCG,ATAT],[ATAT,TATA]]
我更希望代码是传统的for循环格式,而不是理解
这是所列问题的一小部分here。这部分问题被重新提问,因为前面提供的答案提供了不正确的输出。你知道吗
运行这个
返回此
此任务的核心是从子列表中提取对并计算唯一对的数量。假设您的示例实际上包含字符串,您可以使用
zip(*sub_list)
来获取这些字符串对。然后可以使用set()
删除重复的条目。你知道吗然后可以使用for循环或列表理解将此函数应用于主列表。你知道吗
…或者作为for循环。。。你知道吗
相关问题 更多 >
编程相关推荐