Recursion on list

Pieter van Oostrum pieter-l at vanoostrum.org
Thu Nov 4 08:11:37 EDT 2021


ast <ast at invalid> writes:

>> li = []
>> li.append(li)
>> li
> [[...]]
>
>>li[0][0][0][0]
> [[...]]
>
> That's funny
>

You made a list whose only element is itself.

In [1]: li = []

In [3]: li.append(li)

In [4]: li[0] is li
Out[4]: True

-- 
Pieter van Oostrum <pieter at vanoostrum.org>
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]


More information about the Python-list mailing list