2017-05-19 2 views
-4

[{ "タイムスタンプ":1495126913.0、 "CLIENT_IP": "10.200.3.55"、 "REMOTE_HOST": "78.47.139.58"}、{」タイムスタンプ ":1495126913.0、 " client_ip ":" 10.200.3.55 "、" remote_host ":" 201.83.41.11 "}、 {"タイムスタンプ ":1495126913.0、" client_ip ":" 10.200.3.55 "、" remote_host ": "175.106.59.78"}、{"タイムスタンプ":1495126915.0、 "client_ip": "10.200.3.55"、 "remote_host": "175.106.59.78"}、{"タイムスタンプ": 1495126915.0、 "client_ip": "10.200 「remote_host」:「175.106.59.78」}、{"タイムスタンプ":1495126915.0、 "client_ip": "10.200.3.55"、 "remote_host": "78.47.139.58"}、{"タイムスタンプ": 1 "remote_host": "201.83.41.11"}、{"timestamp":1495126917.0、 "client_ip": "10.200.3.55"、 "remote_host": "175.106.59.78"、 "client_ip": "10.200.3.55" }、{"タイムスタンプ":1495126917.0、 "client_ip": "10.200.3.55"、 "タイムスタンプ":1495126917.0、 "client_ip": "10.200.3.55"、 "remote_host": "201.83.41.11" "remote_host": "201.83.41.11"}]パイソン:のみ一致アイテムを保持し、リスト内の項目の残りの部分を残す

Pythonでは、remote_host = 78.47.139.58と一致するすべてのエントリを見つけます。一致するものだけを表示し、リストに保存します。例えばのために :

予想される答え

[{ "タイムスタンプ":1495126913.0、 "CLIENT_IP": "10.200.3.55"、 "REMOTE_HOST": "78.47.139.58"}、{」タイムスタンプ」:1495126915.0、 "CLIENT_IP": "10.200.3.55"、 "REMOTE_HOST": "78.47.139.58"}]

+0

実際の質問は何に使用するのですか? 良い質問を書く方法を理解するために、この文書をお読みください。 https://stackoverflow.com/help/how-to-ask – PaulNUK

答えて

0

あなたは

list_arr= [{"timestamp": 1495126913.0, "client_ip": "10.200.3.55", "remote_host": "78.47.139.58"}, {"timestamp": 1495126913.0, "client_ip": "10.200.3.55", "remote_host": "201.83.41.11"}, {"timestamp": 1495126913.0, "client_ip": "10.200.3.55", "remote_host": "175.106.59.78"}, {"timestamp": 1495126915.0, "client_ip": "10.200.3.55", "remote_host": "175.106.59.78"}, {"timestamp": 1495126915.0, "client_ip": "10.200.3.55", "remote_host": "175.106.59.78"}, {"timestamp": 1495126915.0, "client_ip": "10.200.3.55", "remote_host": "78.47.139.58"}, {"timestamp": 1495126915.0, "client_ip": "10.200.3.55", "remote_host": "201.83.41.11"}, {"timestamp": 1495126917.0, "client_ip": "10.200.3.55", "remote_host": "175.106.59.78"}, {"timestamp": 1495126917.0, "client_ip": "10.200.3.55", "remote_host": "201.83.41.11"}, {"timestamp": 1495126917.0, "client_ip": "10.200.3.55", "remote_host": "201.83.41.11"}] 
filtered = [_ for _ in list_arr if _['remote_host'] == '78.47.139.58'] 
print(filtered) 
でそれを行うことができます3210

UPDATED

別のアプローチは、lambda方法

filt = list(filter(lambda x: x['remote_host'] == '78.47.139.58', list_arr)) 
print(filt) 

サンプルデモリンクhttps://repl.it/HSRf/4

+0

ありがとうございます –

関連する問題