[英]How can I get all the disjoint subsets of a list of elements, and if join together it is same as the initial list in python?
[英]how to get list of disjoint cycles with given permutation?(python)
我有一个字典,例如: {1:3, 2:2, 3:,1}
。 我需要获取此置换的不相交周期的列表: [[1,3], [2]]
。
我知道如何获取所有排列,但是我不知道如何删除已有的排列。 对于我的示例,我得到: [[1,3], [2], [3,1]]
。
显而易见的解决方案是从循环的最小元素开始规范化循环表示:
min_index = cycle.index(min(cycle))
canonical = cycle[min_index:] + cycle[:min_index]
根据您检索周期的方式,仅生成规范表示可能会更有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.