将输出字符串转换为列表 - Python

时间:2015-06-05 21:47:31

标签: python list append output text-files

我正在将人类ORF密码子代码文件转换成两个列表,一个是ORF_ID片段,另一个是实际的序列数据。

What I want = separate list of ORF_ID and another data or ['a','b','c']
What I get (represented through variables) = 
['a']
[]
['b']
[]
['c']

当我打印列表时,两者都不是字符串列表,而是许多小列表。

示例:

private static void onEnergyTimer(object source, ElapsedEventArgs e)
    {
        if (energy < pastEnergy - 20) {
            StartCoroutine(SendData());}
}

这总是发生在我的python上。我很乐意帮忙。

1 个答案:

答案 0 :(得分:0)

您正在重置for循环中的列表。

看看这能否为您提供所需内容:

ID_list = []
sequences = []
for i in fasta_file:
    ORF_start = i.find('>')
    if ORF_start >= 0:
        ORF_end = i.find('PERFECT_MATCH', ORF_start)
        ORF_ID = i[ORF_start:ORF_end+13]
        ID_list.append(ORF_ID)
    else:
        sequences.append(i)
print ID_list
print sequences

如果fasta_file

['gattaca >cippalippaPERFECT_MATCHxyz', 'sgnoppa >cippalippaPERFECT_MATCHxyz', 'wslewa >cippalippaPERFECT_MATCHxyz', 'whatever', 'anotherone']

它产生这个输出:

['>cippalippaPERFECT_MATCH', '>cippalippaPERFECT_MATCH', '>cippalippaPERFECT_MATCH']
['whatever', 'anotherone']