When the code is run it prints out all the keys that are the same without their values, even if their values are different. ('firstdict' and 'seconddict' are two dictionaries which have been made in previous functions). The above will compare each value in the dictionary and if its present in the list itll add the corresponding key to an output list. Shared_items = set(firstdict()) & set(seconddict()) This is the code I have written: def compare(firstdict,seconddict): The second test is almost as cheap as an identity test on the values objects themselves. I need to compare the two dictionaries, and eliminate from dict2 any key/value pair already present in dict1. I'm trying to compare two dictionaries by comparing the keys, if two keys in the two seperate dictionaries are the same the program should check if the values are also the same, if they are not the same the program should identify that. We can meaningfully define equality two ways: two values objects are equal if they contain the same elements, the same number of times, in any order or two values objects are equal if they both are views of the same dict.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |