One thought on “Udacity – Intro to Computer Science – Python – Deep Reverse”
Hey Johnny, its my 2nd time on your blog and i really find it useful in bouncing my thoughts off your alternate solutions. Thanks for clearly listing your thought process!
I didn’t google the usage of the for loop to do reverse scans but came up with the idea of using the reverse method of lists to perform the same purpose. Below is my code but i can’t seem to understand why my interim output works and the final output does not. If you have time, let me know your thoughts? Cheers!
def deep_reverse(a_list):
new_list = []
a_list.reverse()
if not is_list(a_list):
return a_list
else:
#print ‘a_list is ‘ + str(a_list)
for entry in a_list:
#print ‘checking… ‘ + str(entry)
if is_list(entry):
#print ‘RECURSE! found a list ‘ + str(entry)
deep_reverse(entry)
new_list.append(entry)
#print ‘new_list is ‘ + str(new_list)
Hey Johnny, its my 2nd time on your blog and i really find it useful in bouncing my thoughts off your alternate solutions. Thanks for clearly listing your thought process!
I didn’t google the usage of the for loop to do reverse scans but came up with the idea of using the reverse method of lists to perform the same purpose. Below is my code but i can’t seem to understand why my interim output works and the final output does not. If you have time, let me know your thoughts? Cheers!
def deep_reverse(a_list):
new_list = []
a_list.reverse()
if not is_list(a_list):
return a_list
else:
#print ‘a_list is ‘ + str(a_list)
for entry in a_list:
#print ‘checking… ‘ + str(entry)
if is_list(entry):
#print ‘RECURSE! found a list ‘ + str(entry)
deep_reverse(entry)
new_list.append(entry)
#print ‘new_list is ‘ + str(new_list)
a_list.reverse()
return new_list