У меня есть список словарей следующей структуры:
myList=[{"ID": someString, "sequence": someString2, "quality":[5,6,7]},{...,'quality':[55,66,77]},...]
Качество имеет список чисел в качестве значения.Первое число представляет качество в позиции 0, второе в позиции 1 и т. Д.
Я хочу создать словарь качества для позиции следующей структуры:
qualityDict={0:[5,55], 1:[6,66],2:[7,77] etc}
myИдея:
qualityDict={}
for entryDict in myList:
qualityDict={pos:[entryDict['quality'][pos]] if pos not in qualityDict.keys() else qualityDict[pos].append(entryDict['quality'][pos]) for pos in range(0,len(entryDict['quality']))}
QualityDict создается как словарь pos: [value] для каждого pos в диапазоне (0, длина текущего качества).Если ключ еще не присутствует в dict, он установлен и значение установлено, если он присутствует, я хочу добавить к значению.
Итак, после первой итерации, например, у меня естьДикт с 0,1,2,3 .... длина первого качества (которое было повторено) в качестве ключей, и каждый ключ имеет список с одним значением.Во второй итерации я хочу добавить текущее качество к списку существующего значения.
Я получаю сообщение об ошибке для добавляющейся части: у объекта 'NoneType' нет атрибута append
Чтоя скучаю?Спасибо:)
ОБНОВЛЕНИЕ: myList, из-за которого произошла ошибка:
[{'name': '@SRR587217.1 1 length=489', 'sequence': 'NTCCGGATGATGTCGCTGTTGCTGACAATGGTAATACGTTGACGGGGCAATATGCAGTTCGCTGCATACCGGTCCGACCCCGTACTGCTCACGCAGCTTATCCAGCAGTGGCATCATTTTTTCCAGAGGCGGTCGAACTCCGCCTTCGCAAAAAAAAAGGGAGCCCGGCGGAGGAGAACGTTACTGCGGCGGAGGTTACGATTTTTCCGGTTCCGCTCCTTTAGAAGCCGGACGTCTACCCGGCTCTTTTTGCTGAACGTCAGCGTCTGAAAGAGCTGGAACGTGAAAATCGTGAACTGCGCCGCAGTAACGATATCCTTCGCCAGGCTTCCGCTTATTTTGCGAAGGCGGAGTTCGACCGCCTCTGGAAAAAATGATGCCACTGCTGGATAAGCTGCGTGAGCAGTACGGGGTCGGACCGGTATGCAGCGAACTGCATATTGCCCCGTCAACGTATTACCATTGTCAGCAACAGCGACATCATCCGGA', 'optional': '+SRR587217.1 1 length=490', 'quality': [2, 20, 27, 30, 30, 30, 30, 30, 35, 33, 35, 35, 35, 35, 33, 35, 38, 38, 38, 38, 38, 38, 40, 40, 40, 39, 39, 40, 40, 40, 40, 37, 38, 37, 39, 39, 39, 40, 40, 39, 40, 39, 40, 39, 38, 39, 39, 39, 39, 40, 38, 39, 39, 39, 37, 39, 40, 40, 40, 40, 40, 39, 39, 39, 39, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 36, 39, 39, 39, 39, 39, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 36, 36, 38, 38, 38, 38, 38, 34, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 13, 6, 6, 6, 8, 15, 9, 9, 16, 8, 13, 23, 8, 15, 9, 9, 8, 8, 13, 13, 30, 9, 6, 20, 13, 6, 8, 15, 8, 9, 8, 13, 8, 23, 13, 23, 6, 13, 6, 6, 6, 20, 8, 8, 9, 9, 9, 8, 9, 15, 9, 8, 9, 9, 9, 8, 13, 6, 6, 6, 6, 6, 6, 15, 9, 9, 9, 8, 8, 9, 15, 8, 30, 9, 9, 9, 8, 13, 19, 6, 15, 9, 8, 13, 8, 13, 6, 16, 25, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 13, 6, 13, 15, 23, 9, 9, 9, 16, 9, 8, 6, 6, 13, 15, 9, 25, 9, 9, 9, 30, 30, 32, 32, 30, 33, 33, 33, 35, 35, 35, 35, 35, 35, 35, 35, 38, 38, 38, 38, 38, 38, 39, 40, 39, 40, 40, 39, 39, 39, 40, 39, 40, 39, 39, 40, 39, 40, 40, 40, 39, 39, 39, 39, 37, 38, 39, 38, 37, 36, 37, 36, 34, 37, 32, 35, 39, 37, 39, 40, 39, 39, 37, 39, 33, 37, 38, 39, 39, 40, 37, 39, 39, 39, 39, 39, 39, 39, 39, 39, 35, 35, 36, 39, 39, 39, 39, 35, 37, 37, 39, 39, 38, 20, 32, 32, 36, 36, 36, 38, 38, 38, 36, 38, 38, 38, 38, 38, 33, 35, 29, 26, 34, 38, 38, 36, 38, 36, 34, 36, 34, 36, 38, 38, 38, 36, 36, 36, 30, 30, 36, 38, 36, 38, 36, 38, 36, 36, 38, 38, 38, 38, 36, 34, 36, 34, 36, 38, 38, 38, 38, 38, 38, 38, 34, 36, 36, 36, 38, 32, 32, 35, 32, 34, 27, 29, 35, 35, 17, 23, 32, 13, 19, 8, 25, 34, 36, 38, 38, 38, 38, 29, 35, 34, 34, 36, 34, 34, 34, 36, 25, 9, 30, 34, 36, 30, 27, 23, 36, 34, 34, 34, 38, 13, 24, 34, 34, 34, 38, 30, 34, 30, 30, 34, 30, 34, 36, 34, 36, 36, 36, 9, 24, 30, 36, 29, 23, 29, 17, 23, 30, 36, 36, 30, 30, 36, 35, 38]}, {'name': '@SRR587217.2 2 length=463', 'sequence': 'NACGAACCGATTCTGTTTGGTCTGCCAATTATCATGAACCCGGTGATGTTTATCCCGTTTGTACTGGTACAACCGATTCTGGCGGCAATCACCCTGGCAGCGTACTACATGGGCATTATTCCTCCGGTGACCAATATTGCACCGTGGACCATGCCAACCGGTCTGGGAGCCTTCTTTAACACCAACGGTAGCGTCGTCGCATTGCTGGTTGCACTCTTCAACCTTGGTATCGCAACGTTAATTAATTAACGTTGCGATACCAAGGTTGAAGAGTGCAACCAGCAATGCGACGACGCTACCGTTGGTGTTAAAGAAGGCTCCCAGACCGGTTGGCATGGTCCACGGTGCAATATTGGTCACCGGAGGAATAATGCCCATGTAGTACGCTGCCAGGGTGATTGCCGCCAGAATCGGTTGTACCAGTACAAACGGGATAAACATCACCGGGTTCATGATAATTGGC', 'optional': '+SRR587217.2 2 length=486', 'quality': [2, 20, 27, 30, 30, 30, 28, 27, 27, 27, 31, 35, 30, 33, 35, 30, 37, 37, 37, 36, 37, 37, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 34, 37, 39, 39, 36, 29, 34, 36, 39, 39, 37, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 37, 38, 39, 39, 39, 39, 38, 38, 39, 39, 39, 39, 39, 35, 34, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 37, 37, 37, 37, 37, 37, 37, 36, 37, 37, 36, 37, 36, 25, 29, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 36, 37, 37, 37, 33, 34, 34, 34, 36, 32, 35, 26, 29, 36, 36, 37, 36, 37, 37, 36, 37, 37, 36, 36, 37, 37, 37, 35, 36, 37, 35, 36, 37, 37, 37, 37, 37, 37, 37, 34, 36, 34, 32, 26, 35, 35, 35, 36, 36, 32, 36, 36, 37, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 36, 37, 37, 36, 36, 35, 32, 30, 32, 36, 29, 30, 32, 35, 35, 36, 35, 35, 23, 36, 36, 37, 37, 37, 37, 37, 36, 37, 36, 23, 9, 25, 32, 36, 36, 36, 37, 37, 36, 36, 30, 34, 36, 36, 32, 30, 30, 36, 36, 36, 36, 36, 36, 26, 29, 32, 36, 9, 23, 34, 37, 30, 30, 30, 32, 30, 33, 33, 30, 35, 35, 35, 35, 35, 35, 35, 35, 37, 37, 37, 37, 37, 37, 34, 37, 39, 39, 40, 40, 39, 37, 37, 39, 40, 39, 38, 39, 37, 36, 37, 37, 39, 39, 39, 39, 39, 39, 39, 39, 35, 29, 29, 34, 36, 39, 39, 39, 40, 35, 26, 36, 36, 37, 36, 37, 32, 36, 39, 39, 39, 39, 39, 39, 39, 37, 37, 39, 39, 39, 39, 39, 39, 39, 37, 35, 34, 36, 32, 36, 33, 31, 35, 35, 36, 36, 36, 37, 36, 37, 37, 37, 33, 31, 34, 36, 36, 32, 33, 34, 36, 37, 36, 36, 36, 34, 32, 36, 32, 34, 32, 35, 30, 26, 35, 36, 37, 37, 25, 32, 36, 37, 37, 36, 36, 32, 36, 37, 36, 36, 36, 36, 36, 36, 36, 35, 37, 36, 29, 36, 37, 36, 36, 36, 37, 30, 32, 36, 30, 25, 34, 36, 35, 35, 35, 35, 29, 36, 34, 34, 36, 36, 36, 23, 32, 29, 32, 36, 36, 37, 37, 37, 32, 34, 36, 30, 25, 32, 36, 36, 36, 36, 36, 36, 37, 36, 25, 34, 36, 36, 36, 36, 36, 9, 30, 30, 29, 23, 23, 32, 25, 34, 32, 32, 36, 34, 9, 25, 34, 34, 36, 37]}, {'name': '@SRR587217.4 4 length=460', 'sequence': 'NTCCATGACTTCTGCACGCGTCGGCATCGGGTTAGTAATCATTGACTCCATCATCTGGGTCGCCGTGATTACCGCTCGGTTTAGCTGACGCGCACGACGGATCAACGCTTTCTGAATGCCGACCAGTTCCGGGTCGCCAATTTCCACACCGAGGTCGCCACGTGCAACCATTACCACGTCAGAGGCGAGGATGATGTCATCCATTGCATCCTGGCTGCAAACGGCTTCCGCACGTTCAACCTTGGCAACAAGTGATGCGAAAATTGTTGCCAAGGTTGAACGTGCGGAAGCCGTTTGCAGCCAGGATGCAATGGATGACATCATCCTCGCCTCTGACGTGGTAATGGTTGCACGTGGCGACCTCGGTGTGGAAATTGGCGACCCGGAACTGGTCGGCATTCAGAAAGCGTTGATCCGTCGTGCGCGTCAGCTAAACCGAGCGGTAATCACGGCGACCCAG', 'optional': '+SRR587217.4 4 length=502', 'quality': [2, 20, 20, 30, 30, 30, 33, 33, 35, 35, 35, 35, 35, 35, 35, 35, 38, 38, 38, 38, 37, 37, 39, 39, 39, 39, 39, 40, 39, 39, 39, 37, 39, 39, 40, 38, 38, 39, 40, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 39, 39, 40, 40, 40, 37, 39, 37, 39, 39, 39, 36, 39, 39, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 35, 39, 39, 39, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 34, 38, 38, 38, 38, 38, 38, 38, 38, 36, 38, 38, 38, 38, 38, 38, 34, 32, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 34, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 23, 25, 34, 36, 36, 38, 36, 36, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 36, 38, 38, 38, 34, 38, 38, 38, 38, 38, 38, 38, 38, 35, 23, 29, 38, 38, 38, 38, 29, 35, 38, 36, 36, 36, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 36, 30, 30, 30, 30, 30, 33, 33, 32, 35, 35, 35, 35, 35, 35, 35, 35, 38, 38, 38, 38, 38, 38, 40, 40, 40, 39, 40, 39, 40, 39, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 39, 34, 37, 39, 39, 39, 38, 39, 39, 40, 39, 37, 37, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 39, 38, 39, 40, 39, 40, 38, 39, 39, 34, 35, 36, 39, 39, 39, 39, 39, 30, 35, 35, 37, 37, 37, 35, 37, 39, 37, 37, 38, 38, 38, 38, 37, 37, 37, 36, 38, 38, 38, 33, 33, 38, 38, 36, 38, 34, 36, 34, 36, 36, 38, 36, 38, 38, 38, 36, 36, 38, 38, 38, 38, 38, 38, 35, 38, 38, 27, 32, 30, 34, 38, 36, 38, 38, 38, 38, 38, 23, 34, 38, 38, 36, 36, 34, 36, 38, 38, 38, 36, 34, 29, 36, 36, 36, 34, 34, 38, 36, 38, 35, 38, 38, 38, 38, 38, 19, 23, 34, 36, 36, 30, 34, 16, 30, 36, 34, 29, 17, 23, 35, 35, 35, 15, 19, 23, 34, 34, 34, 36, 36, 34, 32, 38, 38, 23, 32, 38, 38, 38]}]
С уважением @balderman, примеры взяты у него