Issue
I got this error while playing around after reading Guido's blog "Tail Recursion Elimination."
I was curious if there was a non-recursive limitation on nested dictionaries and, I did get an error message but only under a very specific circumstance using an IPython console.
There is no error if I lower the xrange (100 works). What's going on here?
thing = {}
thing2 = thing
for x in xrange(500):
thing2[x] = {}
thing2 = thing2[x]
thing
output:
Traceback (most recent call last):
File "<ipython-input-83-0b6d347b01d4>", line 1, in <module>
thing
File "C:\Python27\lib\site-packages\IPython\core\displayhook.py", line 255, in __call__
self.log_output(format_dict)
File "C:\Python27\lib\site-packages\IPython\core\displayhook.py", line 227, in log_output
format_dict['text/plain']
KeyError: 'text/plain'
repr(thing)
Out[84]: '{0: {1: {2: {3: {4: ....{497: {498: {499: {}}}}}}}}'
Solution
It definitely is an IPython issue. If you try to display the "thing", it fails (in Python3 / IPython 4 with another error message). However, it is perfectly valid object.
This (5 million levels) is ok (although it takes a few seconds to create):
thing = {}
thing2 = thing
for x in range(5000000):
thing2[x] = {}
thing2 = thing2[x]
thing;
Answered By - honza_p
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.