Python Error: maximum recursion depth exceeded in comparison in list -


so here construct

#list1 , list2 list1 = [(true,), (true,)] list2 = [(true,), (true,)] #transformation list1[0] = list2 list1[1] = list1 list2[0] = list1 list2[1] = list2 

which gives:

#result #list1 = [ list2 , list1 ] #list2 = [ list1 , list2 ] 

when run code

>>>list2 in list1 true >>>list1 in list1 runtimeerror: maximum recursion depth exceeded in comparison 

i believe error occurs because getting actual value of list1 comparison results in endless loop. however, list2 not result in error despite being constructed similarly.

so question is, why there discrepancy in error? shouldn't "list2 in list1" cause error too?

if

list = [1,2,3] list.append(list) 

it doesn't this:

list.append([1,2,3]) 

that'd creating new list. appends "reference" list. because copying things not fundamental types want (php jab removed)

so do

list.append(4) 

now:

print(list[3][4]) 

will show 4, 3rd thing (4th start @ zero) list reference, @ that's 4th (5th) 4 appended.

list list[3] 

is true, refer same actual lits.

the recursion happens same reason can't print(list), starts looking, ends looking in endlessly.

it ends because python has max stack depth, default 500 think, can have function call function call function ..... 497 more times. yours never terminate hits wall.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -