[Python-ideas] Implement `itertools.permutations.__getitem__` and `itertools.permutations.index`

Ram Rachum ram.rachum at gmail.com
Wed May 7 19:21:25 CEST 2014


Hi Tal,

I'm using it for a project of my own (optimizing keyboard layout) but I
can't make the case that it's useful for the stdlib. I'd understand if it
would be omitted for not being enough of a common need.


On Tue, May 6, 2014 at 6:40 PM, Tal Einat <taleinat at gmail.com> wrote:

> On Tue, May 6, 2014 at 3:45 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> > On 6 May 2014 10:35, Tal Einat <taleinat at gmail.com> wrote:
> >>> 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
> >
> > For large N, this is much slower than itertools.permutations when you
> > only want the first few entries.
>
> If someone just wants the first few entries, they probably aren't
> worried about it being super fast. And if they were, they could just
> iterate to get the first permutations.
>
> As for getting anything past the first few permutations (e.g. an
> arbitrary one), factorial decomposition would be faster by several
> orders of magnitude than iterating from the beginning. For relatively
> large permutations, iterating from the beginning could be unfeasible,
> while factorial decomposition would still take far less than a second.
>
> The real question IMO is if this is useful enough to bother including
> in the stdlib. For example, I don't think it would pass the "potential
> uses in the stdlib" test. Perhaps Ram (the OP) has some actual
> use-cases for this?
>
> - Tal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140507/e9dce7c1/attachment.html>


More information about the Python-ideas mailing list