Python dictionary access ends up as a typeerror

I’m trying to change an specific part of a dictionary, using Python 3.9 and VS Code terminal, but in change part,

 elif choice=='2':
                    part_name = input('Which part are you willing to change?n(CaSe SeNsEtIvE)nname--age--score--ID? ')
                    if part_name in list_keys:
                        new_value = input("New value? ")
                    else:
                        print('part not found!')
                        ending()
                    listname[final[part_name]] = new_value
                    ending()

it returns an error TypeError: string indices must be integers when I try to access the value in the dict. What’s the problem? Note that strip_name.delspace is a module of mine that removes spaces in an string.

import os, msvcrt, strip_name
list_keys, listname = ['name', 'age', 'score', 'ID'], {'AsgharAkbari':{'name':"Asghar Akbari",'age': 28,'score': 86,'ID':23897},'amirrezavavsari':{'name':"amirreza vavsari",'age':15,'score': 94,'ID':53614}}
   

 def delete():
        os.system('cls')
        print("which student are you willing to delete? (print back to go back)")
      
            del_name = input("enter fullname(CaSe SeNsEtIvE): ")
       
            final = strip_name.delspace(del_name)
            if final in listname.keys():
                choice = input('1- Delete fullyn2-change a part')
                if choice=='1':
                    del listname[final]
                    ending()
                elif choice=='2':
                    part_name = input('Which part are you willing to change?n(CaSe SeNsEtIvE)nname--age--score--ID? ')
                    if part_name in list_keys:
                        new_value = input("New value? ")
                    else:
                        print('part not found!')
                        ending()
                    listname[final[part_name]] = new_value
           

Answer

In listname[final[part_name]], final is a string, and you are trying to index it with part_name, which is also a string. Maybe you meant listname[final][part_name], which accesses the value of the key part_name in the dictionary at key final in listname?