一组类,将整数映射到特定的组合、排列和项的子集,反之亦然。
trotter的Python项目详细描述
欢迎使用trotter,这是一组用于表示排列的python 3类 常用于组合数学。
类是根据顺序是否重要和 项目是否可以重复使用。
Class | Order Important | Reuse Allowed |
---|---|---|
Amalgams | Yes | Yes |
Permutations | Yes | No |
Selections | No | Yes |
Combinations | No | No |
还存在子集和化合物类,它们分别表示未指定长度的组合和排列。
这些类的实例是包含所有可能安排的可索引伪列表。 因为可能的安排数量会随着项目数量的增加而快速增长 可用项和一次获取的项目数,实例实际上并不存储所有 但实际上是整数和排列之间映射的容器。这个 使创建包含大量安排的实例成为可能。
有关详细信息,请参见trotter wiki。
示例会话:
- ::
>>> # Import the Combinations class. ... from trotter import Combinations >>> >>> # A list of words. ... someWords = ["the", "parrot", "is", "not", "pining"] >>> >>> # A representation of 3-combinations of these words. ... c = Combinations(3, someWords) >>> >>> # Exactly what is c? ... print(c) Indexable pseudo-list containing 10 3-combinations of ['the', 'parrot', 'is', 'not', 'pining']. >>> >>> # How many 3-combinations are there, again? ... len(c) 10 >>> # Let's see them! ... for combo in c: ... print(combo) ... ['the', 'parrot', 'is'] ['the', 'parrot', 'not'] ['the', 'parrot', 'pining'] ['the', 'is', 'not'] ['the', 'is', 'pining'] ['the', 'not', 'pining'] ['parrot', 'is', 'not'] ['parrot', 'is', 'pining'] ['parrot', 'not', 'pining'] ['is', 'not', 'pining']