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.
...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...
...sort() keyword arguments - sort() now accepts keyword arguments cmp, key and reverse sorted() - a new builtin sorted() acts like an in-place list.sort() but can be used in expressions, as it returns a copy of the sequence, sorted. string methods - strings gained an rsplit() method, and the string methods ljust(), rjust() and center() accept an argument to specify the fill character. eval() now accepts any form of object that acts as a mapping as its argument for locals, rather than only accepti...
...sort (records with the same key are left in their original order. Original code using a comparison function: names.sort(lambda x,y: cmp(x.lower(), y.lower())) Alternative original code with explicit decoration: tempnames = [(n.lower(), n) for n in names] tempnames.sort() names = [original for decorated, original in tempnames] Revised code using a key function: names.sort(key=str.lower) # case-insensitive sort Locating: grep sort *.py Replacing Common Uses of Lambda In Python 2.4, t...
...Sort dependencies to ensure reproducible builds for dependency in sorted(metadata_object.dependencies): metadata_file += f'Requires-Dist: {dependency}\n' if metadata_object.optional_dependencies: # Sort extras and dependencies to ensure reproducible builds for option, dependencies in sorted(metadata_object.optional_dependencies.items()): metadata_file += f'Provides-Extra: {option}\n' for dependency in sorted(dependencies): ...
...sort out those which stand no chance of being accepted. Many submission ask for the entire budget of $40,000, many of these will be sorted out as too expensive. Jeremy suggested that some of these might receive just a fraction of their requested funds initially, to let the project start, and see later whether they are worth the money. Stephan asked whether the board could see the proposals; Martin responded that the board had already access. Jeremy observed that the PSF has no privacy statemen...
...sorted cannot be used. On comp.lang.python there are many, many, posts [1] asking about the best way to do this task. It's a little tricky to implement optimally and it would be nice to save people the trouble of figuring it out themselves. Considerations Tim Peters suggests trying to use a hash table, then trying to sort, and finally falling back on brute force [2]. Should uniq maintain list order at the expense of speed? Is it spelled 'uniq' or 'unique'? Reference Implementation I've wri...
...sorted list of keys. Does OrderedDict support indexing, slicing, and whatnot? As a matter of fact, OrderedDict does not implement the Sequence interface. Rather, it is a MutableMapping that remembers the order of key insertion. The only sequence-like addition is support for reversed. A further advantage of not allowing indexing is that it leaves open the possibility of a fast C implementation using linked lists. Does OrderedDict support alternate sort orders such as alphabetical? No. Those...
...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...
...sorting versions, it is much preferable if the versioning spec is such that a human can make a reasonable attempt at that sorting without having to run it against some code. Also there's a problem with the use of dates at the "major" version number (e.g. a version string "20090421") with RPMs: it means that any attempt to switch to a more typical "major.minor..." version scheme is problematic because it will always sort less than "20090421". Last, the meaning of - is specific to Setuptools, whil...
...sorted by amount; others suggested to simply order sponsors by date. Marc-Andre proposes to sort them by level, then by date. Another suggestion was to use t-shirts and other merchandise to generate donations, e.g. have $2 per t-shirt go to the PSF and use cafepress.com for the processing. Stephan Deibel also suggested that companies buy "donations for bug fixes", but it was decided (in the PSC) that this is too much work for the organizers, so they dropped the idea. There was discussion. Jer...
...sorts after any digit, so lexicographic sorting matching a sort by Python version of a wheel file name will be kept. Since PEP 515 (Python 3.6), underscores in numeric literals are ignored. This means that int("3_10") and int("310") produce the same result, and ordering based on conversion to an integer will be preserved. However, this is still a bad way to sort tags, and the point is raised here simply to show that this proposal does not make things worse. Security Implications There are no k...
...sort of high-level command-line parsing help is really nice to have, but not so many that it would take me forever to reimplent the interface several times a fair variety of option types and actions (to use Optik's terminology) (but nothing really arcane or unusual) no positional arguments are expected or allowed -- ie. everything Ripoff needs to know can be taken from command-line options. To keep things concrete, here is Ripoff's help text (as generate...
...sort the result of a generator expression or list comprehension. sorted() covers all use cases. Thread: "Adding sorting to generator comprehension", https://mail.python.org/pipermail/python-3000/2006-April/001295.html Slices and extended slices won't go away (even if the __getslice__ and __setslice__ APIs may be replaced) nor will they return views for the standard object types. Thread: Future of slices https://mail.python.org/pipermail/python-3000/2006-May/001563.html It will not be forb...
...sort of syntactic sugar. It avoids not only the repetition of C, but also simplifies the creation of the dict by allowing it to be expressed as a series of statements. Historically, type instances (a.k.a. class objects) have been the only objects blessed with this sort of syntactic support. The make statement aims to extend this support to other sorts of objects where such syntax would also be useful. Example: simple namespaces Let's say I have some attributes in a module that I access like: ...
...sorts of breakage to be expected. While PEPs must still be evaluated on a case-by-case basis, a PEP may be inappropriate for Python 3000 if its Compatibility Issues section implies any of the following: Most or all instances of a Python 2.X construct are incorrect in Python 3000, and most or all instances of the Python 3000 construct are incorrect in Python 2.X. So for example, changing the meaning of the for-loop else-clause from "executed when the loop was not broken out of" to "executed when...
...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...
...sorted from lowest to highest kind. By definition, int_kinds[-1] is the long kind. float_kinds is a list of the available floating point kinds, sorted from lowest to highest kind. default_int_kind is the kind object corresponding to the Python literal 0 default_long_kind is the kind object corresponding to the Python literal 0L default_float_kind is the kind object corresponding to the Python literal 0.0 Complex Numbers If supported, complex numbers have real and imaginary parts that are floa...
...sorted list of StatisticDiff instances grouped by group_by. See the statistics() method for group_by and cumulative parameters. The result is sorted from the biggest to the smallest by: absolute value of StatisticDiff.size_diff, StatisticDiff.size, absolute value of StatisticDiff.count_diff, Statistic.count and then by StatisticDiff.traceback. dump(filename) method: Write the snapshot into a file. Use load() to reload the snapshot. filter_traces(filters) method: Create a new Snapshot instanc...
...sort this out. There was no news on the state of the Merfin LLC payment. Lemburg asked for the bank account details of the PSF bank account needed for the activities of the Public Support Committee (PSC) in order to accept donations via wire-transfer. Jeremy said he'd call up the bank to find out. 4. Python Conference (PyCon) report Van Rossum reported that the conference organization is moving along well. He has signed the contract and paid 10% of the cost as a deposit. The next 15% are d...
...sort of weird dynamic linker error causes dbmmodule to fail on OSF/1 5.1, at least on the HP test machines. It has been reported that untarring the source tarball using Solaris tar or HP/UX tar can fail. This is caused by some pathnames being too long for the tar shipped by the vendor to handle. Using GNU tar should allow for untarring on Solaris and HP/UX. Test suite bugs Some tests may unexpectedly fail on certain platforms. Here are failures that we know (something) about and intend to fi...