I was happy that the answer came out earlier, but I came back to the starting point and posted the question again... The question now is, is it an address book in which you save the information of 3 friends and then input the information? It's about making the same thing. When I first made it,
friends = {}
for i in range (0,3,1) :
friends = {'name': input('name:')', 'tel':input('phone number:')', 'addr':input('address:')', 'age':input('age:')}
print(friends)
inform = input ('Enter information:')
if inform in friends.keys() :
print( friends[inform])
else :
print('Information missing.')
I made it in this format, but at this time, I thought that only the friend's information that I wrote last came out, not the information of 3 people, so I only needed to modify the friends above.
friends = []
for i in range (0,3,1) :
friends.append({'name': input('name:'), 'tel':input('phone number:'), 'addr':input('address:'), 'age':input('age:')})
print(friends)
inform = input ('Enter information:')
if inform in friends.keys() :
print( friends[inform])
else :
print('Information missing.')
After that, I thought it was completed by getting an answer and revising it, but I would appreciate it if you could tell me what the problem is because keys are only available in the dictionary.
python dictionary list save
Friends is a list of dictionaries. Cannot write keys() function because it is a list.
Why don't you use the for statement to approach the elements in the list one by one?
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.