Rearranging a dictionary based on a function-condition over its items
问题 (In relation to this question I posed a few days ago) I have a dictionary whose keys are strings, and whose values are sets of integers, for example: db = {"a":{1,2,3}, "b":{5,6,7}, "c":{2,5,4}, "d":{8,11,10,18}, "e":{0,3,2}} I would like to have a procedure that joins the keys whose values satisfy a certain generic condition given in an external function. The new item will therefore have as a key the union of both keys (the order is not important). The value will be determined by the