![]() |
passing dictionary to the function - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: passing dictionary to the function (/thread-39008.html) |
passing dictionary to the function - mark588 - Dec-19-2022 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 RE: passing dictionary to the function - menator01 - Dec-19-2022 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 RE: passing dictionary to the function - deanhystad - Dec-19-2022 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"]) |