ここからわかるように、私は、各値が単独で辞書である「メイン」辞書を持っています。ここでは、主題辞書の(2以上あります) "name"の値を互いに比較したいので、例えば "DE、Stuttgart"と "DE、Dresden"とXを持ち、ユニークな "name"値左。Python - 複数の辞書を比較して重複する値を削除するにはどうすればよいですか?
たとえば、私はx for x in y if x['key'] != None
構造を知っていますが、私の知る限り、これを使って単一の辞書をフィルタリングすることしかできません。
入力:
"DE, Stuttgart": [
{
"url": "http://twitter.com/search?q=%23ISIS",
"query": "%23ISIS",
"tweet_volume": 21646,
"name": "#ISIS",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%22Hans+Rosling%22",
"query": "%22Hans+Rosling%22",
"tweet_volume": 44855,
"name": "Hans Rosling",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%22Betsy+DeVos%22",
"query": "%22Betsy+DeVos%22",
"tweet_volume": 664741,
"name": "Betsy DeVos",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=Nioh",
"query": "Nioh",
"tweet_volume": 24160,
"name": "Nioh",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%23FCBWOB",
"query": "%23FCBWOB",
"tweet_volume": 14216,
"name": "#FCBWOB",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%23sid2017",
"query": "%23sid2017",
"tweet_volume": 28277,
"name": "#sid2017",
"promoted_content": null
}
],
"DE, Dresden": [
{
"url": "http://twitter.com/search?q=%22Hans+Rosling%22",
"query": "%22Hans+Rosling%22",
"tweet_volume": 44855,
"name": "Hans Rosling",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%22Betsy+DeVos%22",
"query": "%22Betsy+DeVos%22",
"tweet_volume": 664741,
"name": "Betsy DeVos",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=Nioh",
"query": "Nioh",
"tweet_volume": 24160,
"name": "Nioh",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%23FCBWOB",
"query": "%23FCBWOB",
"tweet_volume": 14216,
"name": "#FCBWOB",
"promoted_content": null
},
{
"url": "http://twitter.com/search?q=%23sid2017",
"query": "%23sid2017",
"tweet_volume": 28277,
"name": "#sid2017",
"promoted_content": null
}
],
出力:
"DE, Stuttgart": [
{
"url": "http://twitter.com/search?q=%23ISIS",
"query": "%23ISIS",
"tweet_volume": 21646,
"name": "#ISIS",
"promoted_content": null
}
],
"DE, Dresden": [
],
どのような構文ですか? –
'null'はPythonコードではありません。このJSONテキストはありますか? –
@ Jean-FrançoisFabreええ、それは確かにそれが –