一组类,将整数映射到特定的组合、排列和项的子集,反之亦然。

trotter的Python项目详细描述


https://bitbucket.org/ram6ler/python_trotter/wiki/trotter_py.png

欢迎使用trotter,这是一组用于表示排列的python 3类 常用于组合数学。

类是根据顺序是否重要和 项目是否可以重复使用。

ClassOrder ImportantReuse Allowed
AmalgamsYesYes
PermutationsYesNo
SelectionsNoYes
CombinationsNoNo

还存在子集和化合物类,它们分别表示未指定长度的组合和排列。

这些类的实例是包含所有可能安排的可索引伪列表。 因为可能的安排数量会随着项目数量的增加而快速增长 可用项和一次获取的项目数,实例实际上并不存储所有 但实际上是整数和排列之间映射的容器。这个 使创建包含大量安排的实例成为可能。

有关详细信息,请参见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']

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
MIME类型多部分/混合的java无对象DCH   Java Swing中单元格和列的间距   java为什么我不能使用For循环从集合中获取元素?   mysql Java餐厅计费系统   java MediaPlayer内存消耗   println Java添加的神秘输出:一些经过评估,一些经过打印   java我应该使用哪个对象?   PHP到Java论坛游戏集成   通过GeoNetwork上的java http post请求获取XML响应   java为什么类名与使用“==”的内部字符串比较冲突?   java反应。js如何定义自定义id,而不是在html中显示reactselect1value   java中的拼字数组   java如何使ScheduledExecutorService在其计划任务取消时自动终止   java查询未正确执行   IBatis+Java:检索HashMap   要读取的加密Java代码。txt文件并转换为二进制表示形式   Java Web Start应用程序自动加载   java Swing重写对象的paintComponent