Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Why use list(temp_list) in Python answer

Frank

Jul 26, 2023

I found that without list() or. copy(), we will have repeat subarrays

result.append(list(temp_list))

0

0

Comments
Comments
T
Tom 2 years ago

Without list(), we are adding a reference of "temp_list" to the "results". So if we change anything in temp_list further down the for loop, all the references will change as well. With list(), we are now creating a new array without any reference to "temp_list". So mess...