Infinitely nested containers
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Nov 23 00:59:00 EST 2014
Ethan Furman wrote:
> On 11/21/2014 08:43 PM, Steven D'Aprano wrote:
>> random832 at fastmail.us wrote:
>>>
>>> I think I tried on at least one python version and printing the tuple
>>> crashed with a recursion depth error, since it had no special protection
>>> for this case the way list printing does.
>>
>> It works fine now (Python 3.3).
>>
>> py> L = []
>> py> t = (L, None)
>> py> L.append(L)
>> py> L.append(t) # For good measure.
>> py> print(t)
>> ([[...], (...)], None)
>
> This is a tuple in a list in a tuple, not a tuple in a tuple.
Really? I hadn't noticed.
*wink*
It's still a tuple in itself, recursively, and the tuple to str conversion
routine still has to deal with the fact.
--
Steven
More information about the Python-list
mailing list