[Tutor] permutations?

Hugo Arts hugo.yoshi at gmail.com
Wed Dec 1 23:55:51 CET 2010


On Wed, Dec 1, 2010 at 11:45 PM, Alex Hall <mehgcap at gmail.com> wrote:
> Hi all,
> I am wondering if there is a python package that will find
> permutations? For example, if I have (1, 2, 3), the possibilities I
> want are:
> 12
> 13
> 23
> 123
> 132
> 231
>
> Order does not matter; 21 is the same as 12, but no numbers can
> repeat. If no package exists, does someone have a hint as to how to
> get a function to do this? The one I have right now will not find 132
> or 231, nor will it find 13. TIA.
>

Does order matter or not? You say (2, 1) == (1, 2) but you do list (1,
2, 3) and (1, 3, 2) as separate, so order does matter there. Be
consistent.

You probably want to look at the itertools.permutations and
itertools.combinations functions.

Hugo


More information about the Tutor mailing list