I have a python dict with nested entries, like this:
[{
"id": "lorem",
"name": "lorem",
"info": "lorem",
"system":
{
"0": {"0": "initial question", "1": "lorem", "2": "lorem"},
"A": {"n":"lorem", "n":"lorem"}
},
"result": {"n":"lorem", "n":"lorem"}
}]
Via an input from the console I want to find the id of my dict and continue from there
my code so far:
query = input("Type in the id: ", )
while True:
for i in range(len(data)):
if query in data[i]["id"]:
print(" ")
print("You have selected:", data[i]["name"])
break
if query:
print("Classification not listed! Try again")
print(" ")
query = input("Type in the classification: ", )
continue
#continue here with the code
I know that my problem is the for loop and that I should let my code try to iterate through my json dict until an id is found, and that it should only print the "Classification not listed!" statement if my query input did not match with any id in my data.
However, I cant figure out the correct way.
source https://stackoverflow.com/questions/75795503/iterate-trough-json-dict-until-entry-is-found-or-pass-error-with-python
Comments
Post a Comment