I'm trying to figure out how to use the data a user enters as input to get information from a TinyDB DB.
My DB looks something like this:
{"_default": {"1": {"switch": "n9k-c9372px", "names": ["nexus 9372px", "nexus 9372-px", "nexus9372px", "n9372px", "n9k-c9372px"], "fex_comp": ["2224tp", "2232pp"]}, "2": {"switch": "n9k-c9396px", "names": ["nexus 9396px", "nexus 9396-px", "nexus9396px", "n9396px", "n9k-c9396px"], "fex_comp": ["2232tm-e", "2248tp"]}}}
Basically, the DB is the result of two dictionaries with lists, like these:
{"switch": "switch1", "names": ["name1", "name2", "name3"], "fex_comp":["fex1", "fex2", "fex3"]
My idea is the following:
- To have a prompt asking for a switch model (q= input("Tell me the model")).
- Take the input (q) from the user, and check if it matches any of the "names" in the database.
- If it does, then print the fex_comp list, the whole list. Otherwise, print a different message.
I understand how to form the if, else, statements and also how to use for loops, but I haven't managed to figure out how to do what I describe above.
Any help is much appreciated!
Edvard