Python Forum
passing dictionary to the function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing dictionary to the function
#1
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
Reply
#2
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 welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
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"])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Passing flags to python script, through a function xbit 4 3,994 Apr-20-2021, 06:32 AM
Last Post: ndc85430
  Writing a lambda function that sorts dictionary GJG 1 2,028 Mar-09-2021, 06:44 PM
Last Post: buran
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,298 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Passing argument from top-level function to embedded function JaneTan 2 2,273 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  passing variable to function Rejoice 4 2,886 Sep-11-2020, 03:27 AM
Last Post: Pleiades
  Mathplotlib - passing reference to axs to function qmfoam 5 2,968 Aug-17-2020, 09:02 PM
Last Post: qmfoam
  Passing variable to another function JonnyDriller 10 3,788 Feb-05-2020, 03:46 AM
Last Post: JonnyDriller
  Passing Values of Dictionaries to Function & Unable to Access Them firebird 3 2,596 Aug-03-2019, 10:25 PM
Last Post: firebird
  How to pass a dictionary as an argument inside setup function of unittest nilaybnrj 1 3,212 May-11-2019, 03:18 AM
Last Post: keames
  Passing a local variable outside of a function malonn 8 3,946 Apr-15-2019, 01:50 AM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020