"AttributeError: ‘NoneType’ Object Has No Attribute ‘remove’."


I was stuck in changing the value of the dictionary.
I tried to replace the old value which is inventory[‘backpack’] to what we want ---- inventory[‘backpack’].sort(), so I used the code as follow:
inventory[‘backpack’] = inventory[‘backpack’].sort()
inventory[‘backpack’] = inventory[‘backpack’].remove(‘dagger’)
But it kept reminding me that AttributeError: ‘NoneType’ object has no attribute ‘remove’.
I appreciate for any help.

FAQ: Learn Python: Python Lists and Dictionaries - It's Dangerous to Go Alone! Take This

Hi @z977wang,

Could you please post your full code?



This line could be the cause of your problem. list.sort() has no return value, hence, None, and the cause of the noneType error.

Either sort in place,


or assign a sorted list,

new_list = sorted(old_list)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.