python 3.x - dict1 is the subset of dict2 when dict2 contains same key and value that dict1 has -


example: if = dict(a=1,b=2) b = dict(a=1,b=2, c=3) dict1 subset of dict2 when dict2 contains same key , value dict1 has

what simplest way it?

this have far. there other method return bool determine whether dict1 subset of dict2?

condition = true a, b in dict1.items():     if dict2[a] = b:         condition = false return condition 

i think easiest way take advantage of simplicity of set set. must convert dicts sets of tuples. that, must firstly convert dicts lists of tuples, , create sets. after that, you'll able use method set.issubset:

def issubset(dict1, dict2):     # dict -> list     list1 = list(dict1.items())     list2 = list(dict2.items())      # list -> set     set1 = set(list1)     set2 = set(list2)      return set1.issubset(set2) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -