は、以下のようなものです:マルチレベル辞書構造を定義し、それにデータを挿入する方法は?私は辞書の<strong>defaultdict</strong>【選択構造を用いたマルチレベルのPythonの辞書を作成しようとしています
{
"source1": {
"gene": {
"gene1": {
"location": [
[
10,
200
]
],
"mrna": {
"1": {
"location": [
[
10,
200
]
],
"product": "hypothetical",
"CDS": {
"location": [
[
10,
50
],
[
100,
200
]
]
}
}
}
}
}
}
}
しかし、Pythonで例この種では、我々は前に構造を定義する必要があります任意のデータを挿入します。構造を定義するための
私の試みがある:今すぐ
from collections import defaultdict
dct = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(
lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list)))))))
上記構成にデータを挿入するために、私は上記の定義のフォーマットを作成するためにコードの下に使用しています。
dct['source1']['gene']['gene1']['location'].append([10, 200])
dct['source1']['gene']['gene1']['mrna']['1']['location'].append(['10', '200'])
dct['source1']['gene']['gene1']['mrna']['1']['product'] = 'hypothetical'
dct['source1']['gene']['gene1']['mrna']['1']['CDS']['location'].append([10, 50])
dct['source1']['gene']['gene1']['mrna']['1']['CDS']['location'].append([100, 200])
しかし、何らかのエラーが発生しています。だから誰も私はマルチレベル辞書を作成するのに役立つことができますか?
あなたは壁にぶつかっていることを認識するために何回頭を使って壁を打つ必要がありますか? – alfasin
@alfasin - できませんか? – Arijit
もちろん、それは可能ですが、実際には、dct ['source1'] ['gene'] ['gene1'] ['mrna'] ['1'] ['CDS' ] ['location']。append([100、200]) '? – alfasin