python - How to compare values inside a dictionary to fill up sets() -


dico = {"dico":   {1:"bailler",2:"bailler",3:"percer",4:"calculer",5:"calculer",6:"trouer",7:"bailler",8:"découvrir",9:"bailler",10:"miser",11:"trouer",12:"changer"}} 

i have big dictionary of dictionaries that. want put identic elements in sets. create kind of condition if values of "dico" equal put them in set():

b=[set(1,2,7,9),set(3),set(4,5),set(6,11),set(8),set(10),set(12)] 

i don't know if question has been asked new pythonner don't have keys... ^^

thank you answers

i reverse dictionary , have value set(), return values.

>>> collections import defaultdict >>>>my_dict= {"dico":   {1:"bailler",2:"bailler",3:"percer",4:"calculer",5:"calculer",6:"trouer",7:"bailler",8:"découvrir",9:"bailler",10:"miser",11:"trouer",12:"changer"}} >>> my_other_dict = defaultdict(set) >>> dict_name,sub_dict in my_dict.iteritems():     k,v in sub_dict.iteritems():         my_other_dict[v].add(k) #the value, i.e. "bailler" key                                  #e.g. {"bailler":set([1,2,9,7]),...   >>> [v k,v in my_other_dict.iteritems()] [set([8]), set([1, 2, 9, 7]), set([3]), set([4, 5]), set([12]), set([11, 6]), set([10])] 

of course cynddl has pointed out, if index in list "key", enumerate list , won't have store original data dictionary, nor use sets() indices unique.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -