Enumerating all 3-tuples

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Mar 13 07:01:09 EDT 2018


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 :-)


-- 
Steve




More information about the Python-list mailing list