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

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第三方库


热门话题
在ElasticSearch中将SearchHit转换为Java对象   第三方库类的java重写XmlAdapter   java如何使用动画类获得平滑的动画效果?   Java PDFBox如果文本内容超过PDF的第一页,如何添加新页面?   Java二叉搜索树u根到最近叶的距离   java什么是diff Scanner和BufferedReader   java如何设计不生成并行数组的程序   java多次声明变量会降低执行速度吗?   java如何使用JXLAPI读取下拉列表的值   多线程为什么自定义阻塞队列在Java中不是线程安全的   java在一个变量中每输入1000个单位,就从另一个变量中减去1?   java Mapstruct通用映射器   Java中的类能否确定它是否已被修改?   java如何在MogoOperations聚合函数中定义输出类型?