14. Why can't I do two list functions in one line, to a list in a dictionary?


#1


https://www.codecademy.com/courses/python-beginner-en-pwmb1/2/5?curriculum_id=4f89dab3d788890003000096#

If i write the code I have included in this post. I get this error.

Traceback (most recent call last):
File "python", line 15, in
AttributeError: 'NoneType' object has no attribute 'remove'

If I write the other code I have included in this post, it works fine. Why is that?

I expected to be able to execute two list functions in one line.

#This works
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')

#This doesn't work. Why is that?
inventory['backpack'].sort().remove('dagger')


#2

calling sort function returns None instead of the expected sorted list as sorting takes places in the same list. You can execute multiple functions on the same list provided the return value of one operation is the same or another list.