Dictionary practice problem 6 (I am stucked)

def remove_rows(dic,row_list):
    new=[]
    column=[]
    for key,value in dic.items():
        column.append(key)
        for k,v in value.items():
            if k not in row_list and k not in new:
                new.append(k)
    final={}
    for col in column:
        for index in new:
            print(dic[col][index])

my task was to create a function that returns a new dictionary without the rows that have their index specified in the row_list /second augment in the function created.

Nb. I don’t understand the clean method used as the answer. hence the reason why I attempted to create my own from scratch. I dislike this method because it doesnt give me a chance to appreciate what is going on behind the scene

For my function created above, I got stuck. I have managed to print out the values associated to the indices not in row_list. but how to relate what I have managed to achieve back to the format {column_name: {index: value}} to create a new dictionary which I could return is were am stucked at.

any help to enable me finish up my code and understand the clean and shorter method used in the solution provided is welcomed

Hi!
I followed the similar logic in my solution, so it´s easy to help you to finish yours.
In you last step, when you iterate over the columns you have to instantiate an empty dictionary which will be a value of your final dicationary and you´ll fill it with keys/values while iterating over the indexes.

final={}
    for col in column:
        final[col] = {}
        for index in new:
            final[col][index] = dic[col][index]

As for the suggested solution, thanks to dictionary comprehension it looks clean and explicit, but sometimes it difficult to understand what´s happening behind when you are just starting.
So, my advice would be, first, to rewrite the solution´s code without dictionary comprehensions, only using for-loop operator but keeping the functions as they are. And if it´s still difficult to comprehend, then substitute calling the remove_keys() function inside the remove_rows() function, the one that returns the desired output.