There is a catalog of documents:

documents = [ {"type": "passport", "number": "2207 876234", "name": "Василий Гупкин"}, {"type": "invoice", "number": "11-2", "name": "Геннадий Покемонов"}, {"type": "insurance", "number": "10006", "name": "Аристарх Павлов"} ] 

Need a team that asks for the document number and displays the name of the person to whom it belongs

  • Can you attach your code? What did not work out? - Pavel Durmanov
  • I try to sort through the key and it turns out nonsense, I think in the wrong direction in general I move repl.it/HoVy/1 - user249333
  • Try to iterate over an array - Pavel Durmanov

1 answer 1

 documents = [ {"type": "passport", "number": "2207 876234", "name": "Василий Гупкин"}, {"type": "invoice", "number": "11-2", "name": "Геннадий Покемонов"}, {"type": "insurance", "number": "10006", "name": "Аристарх Павлов"} ] inp = input('Enter number: ') for elem in documents: if elem['number'] == inp: print(elem['name']) 

Option with filter :

 foo = lambda num: list(filter(lambda x: x['number'] == str(num), documents))[0]['name'] 

Using:

 In [33]: foo(10006) Out[33]: 'Аристарх Павлов' 
  • thank you very much! - user249333