I have an array of lists with dicts as below:
[{'key': 'Platform', 'value': 'Test'}, {'key': 'Name', 'value': 'Test1'}, {'key': 'APICall', 'value': 'post'}]
[{'key': 'Platform', 'value': 'Test1'}, {'key': 'APICall', 'value': 'Get'}]
[{'key': 'Platform', 'value': 'Test2'}, {'key': 'Name', 'value': 'Test2'}, {'key': 'APICall', 'value': 'post'}]
for this array I would like to get the lists if keys Platform
and Name
present.
So I would like to get
[{'key': 'Platform', 'value': 'Test'}, {'key': 'Name', 'value': 'Test1'}, {'key': 'APICall', 'value': 'post'}]
and [{'key': 'Platform', 'value': 'Test2'}, {'key': 'Name', 'value': 'Test2'}, {'key': 'APICall', 'value': 'post'}]
I don't know how to achieve this in one most effective way?
I did a very simplistic way which is working, but in the future, if the list count grows then it might take a longer time. Is there any simple and effective way to achieve this?
for arr_keys in arr:
if arr_keys['key'] == "Platform":
platform = arr_keys['value']
if arr_keys['key'] == "Name":
Name = arr_keys['value']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…