在下面的代码片段中,是否有更 Pythonic 的方式来迭代列表中的每个对象,同时增加另一个对象的索引?我经常使用这个成语,认为有更好的方法。
# Creates a dictionary with normalized values for the dataset.
def exp_pull(sample, gene):
sample_name = {genes: values for genes, values in
zip([v for i, (j, k) in set_list[int(sample) - 1:int(sample)]
for v in j], mean_values)}
return round(sample_name.get(gene), 3)
# Pulls normalized expression values for particular genes for all samples.
genes_of_interest = ['ERG', 'ETV1', 'ETV4', 'ETV5']
count = 0
for gene in genes_of_interest:
print '\n'
print genes_of_interest[count], ':'
for file in file_list:
print file, ": ", exp_pull(file_list.index(file) + 1,
genes_of_interest[count])
count += 1