Making a set from dictionary values

后端 未结 2 701
旧巷少年郎
旧巷少年郎 2021-01-12 10:29

I want to create a set from the values of an existing dict

def function(dictionary):
    ... 
    return set_of_values

Say my dictionary lo

2条回答
  •  攒了一身酷
    2021-01-12 10:58

    Just another way to unique out:

     >>> my_dict = {'1': 'Monday', '3': 'Monday', '2': 'Tuesday'}
     >>> {y:x for x,y in my_dict.iteritems()}.keys()
     ['Tuesday', 'Monday']
     >>>
    

提交回复
热议问题