Python Forum

Full Version: passing dictionary to the function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have got a dictionary of multiple npy files together and I want pass this dictionary as a parameter to get a comparison score.
I am not sure how to pass them to the function as 2 different subjs.
as function needs 2 paramters to compare and to print the comparsion score.
Thanks for help
One way
dict1 = {
    'key1': 1,
    'key2': 2
}

dict2 = {
    'key': 1,
    'key4': 4
}

def myfunction (arg1, arg2):
    if arg1 == arg2:
        return 'Dicts are equal'
    return 'Dicts do not match'

print(myfunction(dict1, dict2))
You may also want to look at deepdiff from pypi
I think the OP is asking about something more like this:
stuff = [{'key1': 1, 'key2': 2}, {'key': 1, 'key2: 4}]
or maybe
stuff = {"dict1": {'key1': 1, 'key2': 2}, "dict2": {'key': 1, 'key2: 4}}
Either way you use indexing to get the dictionaries you want to compare.
compare(stuff[0], stuff[1])
compare(stuff["dict1"], stuff["dict2"])