fork download
  1. def query(name):
  2. mylist = [{'name':'book','number':5},{'name':'pen','number':4}]
  3. target = list(filter(lambda mylist: mylist['name'] == name, mylist))
  4. return 'name: {}, number: {}'.format(target[0]['name'], target[0]['number']) if len(target) else 'No result'
  5.  
  6. print(query('pen'))
Success #stdin #stdout 0.02s 9228KB
stdin
Standard input is empty
stdout
name: pen, number: 4