object-oriented programming def __setitem__(selfindexvalue)raise typeerror("use add(to insert value and rely on "the list to put it in the right place"we don' want the user to change an item at given index position (so [nx is disallowed)otherwisethe sorted list' order might be invalidated the typeerror exception is the one used to signify that an operation is not supported by particular data type def __iter__(self)return iter(self __listthis method is easy to implement since we can just return an iterator to the private list using the built-in iter(function this method is used to support the for value in iterable syntax note that if sequence is required it is this method that is used so to convert sortedlistlto plain list we can call list( )and behind the scenes python will call sortedlist __iter__(lto provide the sequence that the list(function requires def __reversed__(self)return reversed(self __listthis provides support for the built-in reversed(function so that we can writefor examplefor value in reversed(iterabledef __contains__(selfvalue)index self __bisect_left(valuereturn (index len(self __listand self __list[index=valuethe __contains__(method provides support for the in operator once again we are able to use fast binary search rather than the slow linear search used by plain list def clear(self)self __list [def pop(selfindex=- )return self __list pop(indexdef __len__(self)return len(self __listdef __str__(self)return str(self __list