How to Solve NameError: name 'attrgetter' is not defined -- operator

Solution: Import the 'attrgetter' module

# Add the following line to the top of your code
from operator import attrgetter

 

For more information:
operator attrgetter