Skip to main content

Pseudo-lists containing arrangements of item selection types that commonly arise in combinatorics, such as combinations, permutations and subsets.

Project description

Welcome to trotter, a set of Python 3 classes for representing arrangements of arrangements commonly encountered in combinatorics.

Classes have been defined according to whether order is important, items may be repeated, and length is specified.

Class Order Important Repetition Allowed Specified Length
Amalgams Yes Yes Yes
Permutations Yes No Yes
Compounds Yes No No
Compositions No Yes Yes
Combinations No No Yes
Subsets No No No

Instances of these classes are indexable pseudo-lists containing all possible arrangements. Since the number of possible arrangements can grow very quickly with the number of items available (and the number of items taken at a time, where applicable), instances do not actually store all arrangements but are rather containers of mappings between integers and arrangements. This makes it possible to create instances that "contain" very large numbers of arrangements.

For more information, please see the trotter wiki.

Example session: pick three words

>>> # Import the Combinations class.
... from trotter import *
>>> # A list of words.
... items = ["the", "parrot", "is", "not", "pining"]
>>> # A representation of 3-combinations of these words.
... combos = Combinations(3, items)
>>> # Exactly what is c?
... print(combos)
A pseudo-list containing 10 3-combinations of ['the', 'parrot', 'is', 'not', 'pining'].
>>> # How many 3-combinations are there, again?
... len(combos)
>>> # Let's see them!
... for combo in combos: 
...   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']

Example session: subsets of letters in a string

>>> # The items can also be the characters in a string.
... items = "spam"
>>> # The subsets of the letters in this word
... # (notice the first is the empty string):
... for subset in Subsets(items):
...   print(subset)


Example session: a looooong pseudo-list!

>>> # How many 10-permutations are there 
... # of the 26 letters in the alphabet?
... letters = "abcdefghijklmnopqrstuvwxyz"
>>> permutations = Permutations(10, letters)
>>> # Just how big is this list?
... print(permutations)
A pseudo-list containing 19275223968000 10-permutations of abcdefghijklmnopqrstuvwxyz.
>>> # Wow! Almost twenty trillion! Luckily it's only a
... # pseudo-list and not really stored on the computer!
... # The word "algorithms" is a ten-letter permutation of letters.
... # What is the index of this word in the list of permutations?
... permutations.index("algorithms")
>>> # Found in a split second - take that, Mathematica!
>>> # Let's check:
... print(permutations[6831894769563])

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for trotter, version 0.9.0
Filename, size File type Python version Upload date Hashes
Filename, size trotter-0.9.0.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View
Filename, size trotter-0.9.0-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page