Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...algorithm to convert the strings to sortable keys, with a parse_version function. From the doc: Convert a version string to a chronologically-sortable key This is a rough cross between Distutils' StrictVersion and LooseVersion; if you give it versions that would work with StrictVersion, then it behaves the same; otherwise it acts like a slightly-smarter LooseVersion. It is *possible* to create pathological version coding schemes that will fool this parser, but they should be very rare in pract...
...sorting to achieve sort-by-value. To allow the four basic possibilities of sorting by key/value and in forward/reverse order, we could add this method: (4) sorted_items(by_value=0, reversed=0) I believe the most common case would actually be by_value=1, reversed=1, but the defaults values given here might lead to fewer surprises by users: sorted_items() would be the same as items() followed by sort(). Finally (as a last resort), we could use: (5) items_sorted_by_value(reversed=0) Implement...
...algorithm for frozensets More compact pickle format (storing only an element list instead of a dictionary of key:value pairs where the value is always True). Use a __reduce__ function so that deep copying is automatic. The BaseSet concept was eliminated. The union_update() method became just update(). Auto-conversion between mutable and immutable sets was dropped. The _repr method was dropped (the need is met by the new sorted() built-in function). Tim Peters believes that the class's construct...
...sorted(iterable, key=noop), etc. (filter, max, and min all accept callables that accept a single argument, as do many of the itertools operations). Making noop() a useful default function in those cases just needs the definition to be: def noop(*args, **kwds): return args[0] if args else None The counterargument to the counterargument is that using None as the default in all these cases is going to be faster, since it lets the algorithm skip the callback entirely, rather than calling it an...
...sort() implementation - this one is a "stable sort" (equal inputs appear in the same order in the output) and faster than before. Tim Peters also changed long int multiplication to use the Karatsuba algorithm, based on a patch by Christopher A. Craig. This speeds up multiplication of very long ints.
...algorithms in a simple and safe way to others, you can argue that providing a scripting language is not worth the effort. However, if you do have that need, as we did, scripting is a no brainer, and it makes complete sense to use a powerful, documented, cross-platform standard such as Python." -- Mustafa Thamer of Firaxis Games, talking about Civilization IV. Quoted on page 18 of the August 2005 Game Developer Magazine. "Python, like many good technologies, soon spreads virally thro...
...sorted_data = sorted(data, key=?.sort_key) given: def sort_key(item): return item.attr1, item.attr2 The new symbol ? is used to refer to the given namespace. It would be a types.SimpleNamespace instance, so ?.sort_key functions as a forward reference to a name defined in the given clause. A docstring would be permitted in the given clause, and would be attached to the result namespace as its __doc__ attribute. The pass statement is included to provide a consistent way to skip inclus...
...algorithm that's currently implemented, but its description of the algorithm is pretty hard to grasp - I had originally documented a different, naive, algorithm and didn't even realize that it didn't always compute the same MRO until Tim Peters found a counterexample. More recently, Samuele Pedroni has found a counterexample showing that the naive algorithm fails to maintain monotonicity, so I won't even describe it any more. Samuele has convinced me to use a newer MRO algorithm named ...
...sort top level developmental releases like X.Y.devN ahead of alpha releases like X.Ya1. This is a far more logical sort order, as projects already using both development releases and alphas/betas/release candidates do not want their developmental releases sorted in between their release candidates and their final releases. There is no rationale for using dev releases in that position rather than merely creating additional release candidates. The updated sort order also means the sorting of dev v...
...algorithm switches to an extended form of C3 linearization, which includes the relevant ABCs in the MRO of the provided argument. The algorithm inserts ABCs where their functionality is introduced, i.e. issubclass(cls, abc) returns True for the class itself but returns False for all its direct base classes. Implicit ABCs for a given class (either registered or inferred from the presence of a special method like __len__()) are inserted directly after the last ABC explicitly listed in the MRO of s...
...Sorting Dictionaries by Value - Griffin This is a small idea that's very important to its proposer, but that IMO attempts to solve a problem that is better solved in some other way, e.g. by teaching newbies the correct algorithm/idiom. I note that the PEP uses sloppy language, e.g. it talks about "sorting a dictionary" while the dictionary itself is never sorted -- the PEP only proposes methods that return the items or keys in sorted order. The PEP also suffers from lack of definiten...
...algorithm 1.3.14.3.2.12). This URL must not be mirrored, and clients must fetch the official serverkey from PyPI directly, or use the copy that came with the PyPI client software. Mirrors should still download the key, to detect a key rollover. For each package, a mirrored signature is provided at /serversig/<package>. This is the DSA signature of the parallel URL /simple/<package>, in DER form, using SHA-1 with DSA (i.e. as a RFC 3279 Dsa-Sig-Value, created by algorithm 1.2.840.1004...
...sorted() builtin function that returns a new sorted list from any iterable. CObjects are now mutable (on the C level) through PyCObject_SetVoidPtr. list.sort() now supports three keyword arguments: cmp, key, and reverse. The key argument can be a function of one argument that extracts a comparison key from the original record: mylist.sort(key=str.lower). The reverse argument is a boolean value and if True will change the sort order as if the comparison arguments were reversed. In addition, th...
...sort order. We figure that you know more about your project than we do, so we give you a set of very flexible tools to mold our software around your project, instead of vice-versa. Background Christian Simms, Botonomy co-founder, and I had worked together for several years, and we used Python for utility-type tasks in larger J2EE projects. We had talked informally a couple of times about building some kind of software product or service. I had just wrapped up a project where the client had no ...
...Algorithm Transition Plan If the algorithm used to hash target and metadata files becomes vulnerable, it SHOULD be replaced by a stronger hash algorithm. The TUF metadata format allows to list digests from different hash algorithms alongside each other, together with an algorithm identifier, so that clients can seamlessly switch between algorithms. However, once support for an old algorithm is turned off, clients that don't support the new algorithm will only be able to install or update package...
...algorithm that's currently implemented, but its description of the algorithm is pretty hard to grasp - I didn't even realize that the algorithm above doesn't always compute the same MRO until Tim Peters found a counterexample. Fortunately, counterexamples can only occur when there are order disagreements in the inheritance graph. The book outlaws classes containing such order disagreements, if the order disagreement is "serious". An order disagreement between two classes is serious wh...
...algorithm, depending on whether the data was in the form of an iterator or sequence. This proved to be a design mistake, as the calculated variance could differ slightly depending on the algorithm used, and variance etc. were changed to internally generate a list and always use the more accurate two-pass implementation. One controversial design involved the functions to calculate median, which were implemented as attributes on the median callable, e.g. median, median.low, median.high etc. Alth...
...algorithm: isclose(a,b) is always the same as isclose(b,a) If a relative closeness test uses only one of the values (such as (1) above), then the result is asymmetric, i.e. isclose(a,b) is not necessarily the same as isclose(b,a). Which approach is most appropriate depends on what question is being asked. If the question is: "are these two numbers close to each other?", there is no obvious ordering, and a symmetric test is most appropriate. However, if the question is: "Is the computed value wit...