The UserDict, defined in the collections module,  is a subclass of the standard dict class. It  provides the same API and functionality as the built-in dict class, but is designed to be subclassed. It can be used to create custom dictionaries with specialized behaviors.

UserDict provides two advantages over the built-in dict class. First, it is easier to subclass since it provides features suited for subclassing Second, the underlying data storage can be changed and customized, allowing for more efficient implementations or using a different data structure to store the dictionary data.

Create custom Dictionaries

To define a custom dictionary,  we create a class derived from the UserDict class through inheritance.The new class can define additional methods to support operations specific to the type of dictionary being created. 

ExampleEdit & Run
from collections import UserDict

class GradeBook(UserDict):
     def __init__(self, data): 
         super().__init__(data)
     def add_student(self, student_name, grade): 
          self[student_name] = grade 

     def delete_student(self, student_name): 
         del self[student_name] 

     def average_grade(self):
          return sum(self.values()) / len(self)

     def top_student(self):

          highest = max(self.values())
          for i in self:
              if self[i] == highest:
                   return i, highest

# Initialize Gradebook 
student_grades = GradeBook({'John': 80, 'Jane': 90, 'Harry': 70}) 
student_grades.add_student('Dave', 95)

# Compute the average for all students
print(student_grades.average_grade()) 

print(*student_grades.top_student())
Output:
83.75Dave 95[Finished in 0.012619473971426487s]

The above example utilizes the UserDict class to manage student grades and provides specific methods for grade-related operations.