def sort_notes_into_folders(notes, folders):
    """
    sorts notes into a dictionary with the folder names as the key

    :param notes:
        A list of notes objects
    :param folders:
        a list of tuples with each tuple holding (folder_id, folder_name)
    :return:
        a dictionary with all the notes, sorted into their folders as well
        as a all key which stores all the notes

    Note 1: the values in the keys is a list of note objects that is correlated
    to the folder name

    Eg. {
        'test_folder': [Note_obj_1, Note_obj_2, ...],
        'all': [all_note_objs]
    }
    """

    # so that when the note gets appended to the dictionary, it will already be sorted
    notes.sort(key=lambda note: note.last_edited, reverse=True)
    folders = dict(folders)
    notes_sorted_by_folders = {'All':[]}

    # to store all the folder_names even when it has no notes
    for folder_id in folders:
        folder_name = folders[folder_id]
        notes_sorted_by_folders.setdefault(folder_name, [])

    for note in notes:
        if note.parent_folder_id != 0: # note has a folder
            folder_name = folders[str(note.parent_folder_id)]
            notes_sorted_by_folders[folder_name].append(note)

        notes_sorted_by_folders['All'].append(note)

    return notes_sorted_by_folders