object-oriented programming str(letters="[' '' '' '' '' '' '' '' ']letters[ returns'ca sortedlist object aggregates (is composed oftwo private attributesa functionself __key((held as object reference self __key)and listself __list lambda functions the key function is passed as the second argument (or using the key keyword argument if no initial sequence is givenif no key function is specified the following private module function is used_identity lambda xx this is the identity functionit simply returns its argument unchangedso when it is used as sortedlist' key function it means that the sort key for each object in the list is the object itself the sortedlist type does not allow the item access operator ([]to change an item (so it does not implement the __setitem__(special method)nor does it provide the append(or extend(method since these might invalidate the ordering the only way to add items is to pass sequence when the sortedlist is created or to add them later using the sortedlist add(method on the other handwe can safely use the item access operator for getting or deleting the item at given index position since neither operation affects the orderingso both the __getitem__(and __delitem__(special methods are implemented we will now review the class method by methodstarting as usual with the class line and the initializerclass sortedlistdef __init__(selfsequence=nonekey=none)self __key key or _identity assert hasattr(self __key"__call__"if sequence is noneself __list [elif (isinstance(sequencesortedlistand sequence key =self __key)self __list sequence __list[:elseself __list sorted(list(sequence)key=self __keysince function' name is an object reference (to its function)we can hold functions in variables just like any other object reference here the private self __key variable holds reference to the key function that was passed inor to the identity function the method' first statement relies on the fact that the or operator returns its first operand if it is true in boolean context (which not-none key function is)or its second operand otherwise slightly longer but