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

Solution: Import the 'operator' module

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

 

For more information:
Python operator