Skip to content
Advertisement

How to look for specific values in a dictionary and return them properly

So I have a list dictionary of dictionaries (lst) that I’m trying to iterate through, compare values, and return the appropriate values.

I have the following code to retrieve 2 arguments given from the command line, compare them through the dictionaries entries, and return the appropriate value:

JavaScript

get_attribute_number(cmd1=sys.argv[1], cmd2=sys.argv[2], lst=data_list)

However, my program is not returning anything. It is supposed to for example if I provide the cmd line arguments python3 program.py [NAME] [ATTRIBUTE], is supposed to query the above data until it finds a match for the name, and return its requested attribute as an integer. Can anyone offer suggestions on why I’m not able to print(int(name[attribute])) for the corresponding napp_name?

Advertisement

Answer

i changes your code a little to be more friendly to user:

JavaScript

basicly thay need to enter just substring to get some results, so this:

JavaScript

outputs only desired data:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement