Enumerating all 3-tuples
Paul Moore
p.f.moore at gmail.com
Tue Mar 13 07:19:00 EDT 2018
On 13 March 2018 at 11:01, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sat, 10 Mar 2018 11:15:49 +0000, Paul Moore wrote:
>
>> On 10 March 2018 at 02:18, MRAB <python at mrabarnett.plus.com> wrote:
> [...]
>>> This might help, although the order they come out might not be what you
>>> want:
>>>
>>> def triples():
>>> for total in itertools.count(1):
>>> for i in range(1, total):
>>> for j in range(1, total - i):
>>> yield i, j, total - (i + j)
>>
>> Mathematically, that's the usual generalisation of Cantor's diagonal
>> argument.
>
> Thanks MRAB. Paul, do you have a reference for that? Wolfram Mathworld is
> not very helpful regarding generalising Cantor's diagonalisation pairing
> function.
>
> (It's not the diagonal argument, that's something else :-)
Sadly, other than my memories of my maths degree from 30 years ago, no
I don't. I'll see if I can dig something out.
Paul
More information about the Python-list
mailing list