[Python-ideas] Implement `itertools.permutations.__getitem__` and `itertools.permutations.index`
Tal Einat
taleinat at gmail.com
Tue May 6 11:35:09 CEST 2014
On Tue, May 6, 2014 at 5:39 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, May 06, 2014 at 07:22:56AM +0900, INADA Naoki wrote:
>
>> I don't think the order of permutation is implementation detail.
>> Python implementations should follow CPython's documented order.
>>
>> https://docs.python.org/3.4/library/itertools.html#itertools.permutations
>
> Hmmm. Well, since the order of permutations is documented, I suppose my
> objection is answered. In that case, it becomes a question of whether or
> not there is an easy way to generate the Nth permutation without having
> to iterate through the previous N-1 permutations.
Yes, it is possible using factorial decomposition of N.
See, for an example: http://stackoverflow.com/a/7919887/40076
- Tal Einat
More information about the Python-ideas
mailing list