Jun-17-2020, 03:12 AM
This is because your functions like rotate_clockwise_90 isn't returning a copy of the list, it's modifying the list and then handing it back. So you only have one list that you're modifying over and over again. And your big list just has that one appended multiple times.
You should decide if your functions should be returning copies, or if they should be modifying the passed-in function. Then either the caller or function can be making a copy.
You should decide if your functions should be returning copies, or if they should be modifying the passed-in function. Then either the caller or function can be making a copy.
outer_list = [] sublist = ['a'] # list brackets here make a new list outer_list.append(sublist) sublist[0] = 'b' # modifying an element of the list, not a new list outer_list.append(sublist) print(outer_list) # If you don't want to modify the passed-in list, make a copy sublist = sublist.copy() sublist[0] = 'c' # This is modifying only the new list, not the old one outer_list.append(sublist) print(outer_list)
Output:[['b'], ['b']]
[['b'], ['b'], ['c']]