У меня есть файл json, который выглядит следующим образом:
{"people": [{"name": "carlota", "birthday": "11/12/1945"},
{"name": "mariana", "birthday": "25/08/1930"},
{"name": "agustina", "birthday": "17/11/1943"}]}
Как я могу воспринимать информацию в «людях» без необходимости создания нового словаря? Потому что это единственный способ, которым я мог это сделать. Вот мой код:
import json
with open("cumple.txt", "r") as f: #cumple.txt is the file where my JSON is
info = json.load(f)
l=[]
s=[]
print('we know the birthday of:')
for i in info['people']:
print(i['name'])
print(i['birthday'])
l.append(i['name'])
s.append(i['birthday'])
c=input("who's birthday want to know ? ")
dictionary = dict(zip(l, s))
if c in l:
print('{} cumple el'.format(c), dictionary[c] )
else:
print('we don\'t know the birthday of {}'.format(c)