python中for循环列表_如何通过Python中的for循环传递列表列表?

我有一份清单清单:

sample = [['TTTT', 'CCCZ'], ['ATTA', 'CZZC']]

count = [[4,3],[4,2]]

correctionfactor = [[1.33, 1.5],[1.33,2]]

我计算每个字符(pi)的频率,将其平方然后求和(然后我计算het = 1 – sum).

The desired output [[1,2],[1,2]] #NOTE: This is NOT the real values of expected output. I just need the real values to be in this format.

问题:我不知道如何在这个循环中传递列表列表(sample,count)来提取所需的值.我以前只使用此代码传递了一个列表(例如[‘TACT’,’TTTT’..]).

>我怀疑我需要添加一个更大的for循环,对样本中的每个元素进行索引(即样本上的索引[0] = [‘TTTT’,’CCCZ’]和样本[1] = [‘ATTA’,’ CZZC’].我不知道如何将其纳入代码中.

**

list_of_hets = []

for idx, element in enumerate(sample):

count_dict = {}

square_dict = {}

for base in list(element):

if base in count_dict:

count_dict[base] += 1

else:

count_dict[base] = 1

for allele in count_dict: #Calculate frequency of every character

square_freq = (count_dict[allele] / count[idx])**2 #Square the frequencies

square_dict[allele] = square_freq

pf = 0.0

for i in square_dict:

pf += square_dict[i] # pf --> pi^2 + pj^2...pn^2 #Sum the frequencies

het = 1-pf

list_of_hets.append(het)

print list_of_hets

"Failed" OUTPUT:

line 70, in

square_freq = (count_dict[allele] / count[idx])**2

TypeError: unsupported operand type(s) for /: 'int' and 'list'er

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值