Can python list and dictionary be nested infinitely? -


recently found python list , dictionary can nested in multiple level this

a = {'a1':[{'a2':{'a3':[4,5,6]}}]} 

so i'd ask there technical limit nested level? if there isn't, there conventional limit nested level, what's it?

the limit memory. given infinite memory can nest python objects infinitely.

demo:

>>> root = lst = [] >>> levels = 0 >>> while true: ...     lst.append([]) ...     lst = lst[-1] ...     levels += 1 ...     if levels % 1000000 == 0:  # every 1 million ...         print levels ...  1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 11000000 # .... # [ slower , slower system starts swap ] # .... traceback (most recent call last):   file "<stdin>", line 1, in <module> memoryerror 

for sake of sanity killed @ 30 million objects though.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -