2017-12-28 9 views
-1

私は辞書をPythonで構造化しようとしています。入力リストは、次のようになります。私は、Pythonでこれを行うことができますどのように私の辞書in Python

[ 
    { 
     "entries": [ 
      { 
       "entries": [ 
        { 
         "title": "Test A", 
         "date": "28.12.17", 
         "name": "Person 1" 
        }, 
        { 
         "title": "Test B", 
         "date": "28.12.17", 
         "name": "Person 1" 
        } 
       ], 
       "name": "Person 1" 
      }, 
      { 
       "entries": [ 
        { 
         "title": "Test C", 
         "date": "28.12.17", 
         "name": "Person 2" 
        }, 
        { 
         "title": "Test D", 
         "date": "28.12.17", 
         "name": "Person 2" 
        } 
       ], 
       "name": "Person 2" 
      } 
     ], 
     "date": "28.12.17" 
    }, 
    { 
     "entries": [ 
      { 
       "entries": [ 
        { 
         "title": "Test E", 
         "date": "29.12.17", 
         "name": "Person 1" 
        }, 
        { 
         "title": "Test E", 
         "date": "29.12.17", 
         "name": "Person 1" 
        } 
       ], 
       "name": "Person 1" 
      }, 
      { 
       "entries": [ 
        { 
         "title": "Test F", 
         "date": "29.12.17", 
         "name": "Person 2" 
        }, 
        { 
         "title": "Test G", 
         "date": "29.12.17", 
         "name": "Person 2" 
        } 
       ], 
       "name": "Person 2" 
      } 
     ], 
     "date": "29.12.17" 
    } 
] 

[ 
    { 
     "title": "Test A", 
     "date": "28.12.17", 
     "name": "Person 1" 
    }, 
    { 
     "title": "Test B", 
     "date": "28.12.17", 
     "name": "Person 2" 
    }, 
    { 
     "title": "Test C", 
     "date": "28.12.17", 
     "name": "Person 1" 
    }, 
    { 
     "title": "Test D", 
     "date": "28.12.17", 
     "name": "Person 2" 
    }, 
    { 
     "title": "Test E", 
     "date": "29.12.17", 
     "name": "Person 1" 
    }, 
    { 
     "title": "Test F", 
     "date": "29.12.17", 
     "name": "Person 2" 
    }, 
    { 
     "title": "Test G", 
     "date": "29.12.17", 
     "name": "Person 1" 
    }, 
    { 
     "title": "Test H", 
     "date": "29.12.17", 
     "name": "Person 2" 
    } 
] 

今、私はこのような出力を生成したいですか?事前にお返事ありがとうございます。

+1

を/stackoverflow.com/help/mcve) – FatihAkici

答えて

0

このお試しください:/:(HTTPS [、最小完全、かつ検証例を作成する方法]あなたの質問のボディにあなたのデータ/コードサンプルを貼り付けてください、とをご覧ください

# Suppose data holds your input 
out = [] 
for date in set([d['date'] for d in data]): 
    d_by_date = {"date": date, "entries":[]} 
    for person in set([d['name'] for d in data]): 
     p_entries = {} 
     p_list = [] 
     for d in data: 
      if d["name"] == person and d["date"] == date: 
       p_list.append(d) 
     p_entries["entries"] = p_list 
     p_entries["name"] = person 
     d_by_date["entries"].append(p_entries) 
    out.append(d_by_date) 
+1

ありがとうございました!あなたは私を大いに助けました! –