Answer the question
In order to leave comments, you need to log in
Python json Find by value, how?
{'cars': [{'model': 'Mitsubishi Lancer', 'id': 5419, 'plate': 'T111TT199'}, {'model': 'Honda VFR750', 'id': 5420, 'plate': 'E222EE177'}]}
Answer the question
In order to leave comments, you need to log in
import json
def model_by_plate(js, plate):
for car in json.loads(js)['cars']:
if car['plate'] == plate:
return car['model']
print(model_by_plate(data, 'E222EE177'))
>>> str1={'cars': [{'model': 'Mitsubishi Lancer', 'id': 5419, 'plate': 'T111TT199'}, {'model': 'Honda VFR750', 'id': 5420, 'plate': 'E222EE177'}]}
>>> filter(lambda x: x['plate']=='E222EE177', str1['cars'])[0]['model']
'Honda VFR750'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question