The Python Oracle

Confusing object reference behaviour in recursion

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puddle Jumping Looping

--

Chapters
00:00 Confusing Object Reference Behaviour In Recursion
01:51 Accepted Answer Score 1
02:10 Thank you

--

Full question
https://stackoverflow.com/questions/4718...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #recursion

#avk47



ACCEPTED ANSWER

Score 1


current_path = current_path[:-1] creates a new list, and binds the name current_path to this newly created list. At that stage, it is no longer the same list as result. Look at the list method pop() instead.