Python Frequently Asked Questions, Release 3.9.5 Chapter 2. Programming FAQ 26 A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and meth- ods of its base classes. This allows an object model to be successively refined by inheritance. You might have a generic$_{Mailbox}$ class that provides basic accessor methods for a mailbox, and subclasses such as$_{MboxMailbox}$ , MaildirMailbox ,$_{OutlookMailbox}$that handle various specific mailbox formats. A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody both the data (attributes) and code (methods) specific to a datatype. Merge them into an iterator of tuples, sort the resulting list, and then pick out the element you want. Isorted =L[:] Isorted.sort(key= lambda s:int(s[10 :15 ])) The technique, attributed to Randal Schwartz of the Perl community, sorts the elements of a list by a metric which maps each element to its “sort value”. In Python, use the$_{key}$ argument for the$_{list.sort()}$ method: The$_{__iadd__}$ succeeds, and thus the list is extended, but even though$_{result}$points to the same object that a_tuple[0] already points to, that final assignment still results in an error, because tuples are immutable. >>> result=a_list.__iadd__ ([1]) >>> a_list=result The object pointed to by a_list has been mutated, and the pointer to the mutated object is assigned back to$_{a_list}$ . The end result of the assignment is a no-op, since it is a pointer to the same object that$_{a_list}$was previously pointing to, but the assignment still happens. Thus, in our tuple example what is happening is equivalent to: >>> result=a_tuple[ 0].__iadd__ (['item']) >>> a_tuple[ 0] =result Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment >>> list1=["what","I'm","sorting","by"] >>> list2=["something","else","to","sort"] >>> pairs =zip (list1, list2) >>> pairs =sorted(pairs) >>> pairs [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', >>> result=[x[1] for x in pairs] >>> result ['else', 'sort', 'to', 'something'] 2.6.1 What is a class? 2.6 Objects 2.5.11 How can I sort one list by values from another list? 2.5.10 I want to do a complicated sort: can you do a Schwartzian Transform in Python?