配对问题
- 有人可能用爱国福换友善福,另一个用友善福换爱国福,那就可以配成一对了,简化说明: A->B, B->A
- 以此类推,A->B, B->C, C->A 也可以配对了
求指导,目前我的配对代码是
from itertools import combinations def check(iterPeople, n): result = [] for peoples in iterPeople: iList, oList = [], [] for people in peoples: iList.append(people['inFu']) #想要的福卡 oList.append(people['outFu']) #给出的福卡 iSet, oSet = set(iList), set(oList) if iSet == oSet and len(iSet) == n: result.append(peoples) return result def matchResult(n): people = people # 登记需求的用户 result = check(combinations(people, n), n) return result