Infinitely nested containers

Rustom Mody rustompmody at gmail.com
Sat Nov 22 06:02:10 CET 2014


On Saturday, November 22, 2014 10:20:36 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Nov 22, 2014 at 3:43 PM, Steven D'Aprano wrote:
> > random832 wrote:
> >
> >> There's no reason not to allow it with tuples, but you can't do it.
> >> Mainly because doing it in a single literal would require special
> >> syntax, whereas you can simply append to a list a reference to itself.
> >
> > You can't append a list to itself in a single expression, you have to create
> > the list first.
> 
> It's possible to have a list directly refer to itself:
> 
> lst = []
> lst.append(lst)

Thats not a single expression; which is possible with a lazy
evaluation language like Haskell.
Prelude> let ones = 1 : ones
Prelude> ones
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
<until the Control-C>



More information about the Python-list mailing list