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.
...sorted() builtin function: >>> sorted(d.iteritems(), key=itemgetter(1), reverse=True) [('b', 23), ('d', 17), ('c', 5), ('a', 2), ('e', 1)] or for just the keys: sorted(d, key=d.__getitem__, reverse=True) ['b', 'd', 'c', 'a', 'e'] Also, Python 2.5's heapq.nlargest() function addresses the common use case of finding only a few of the highest valued items: >>> nlargest(2, d.iteritems(), itemgetter(1)) [('b', 23), ('d', 17)] Motivation A common use of dictionaries is to cou...
...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 accepting a dictionary. There's all sorts of new and shiny evil possible thanks to this litt...
...sorted built-in function both accept a key function for computing sort keys. Unlike the cmp function which gets applied to every comparison, the key function gets applied only once to each record. It is much faster than cmp and typically more readable while using less code. The key function also maintains the stability of the 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())) Alternati...
...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): if ';' in dependency: metadata_file += f'Requi...
...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 statement, so it is unclear who can see the proposals, and in which case. He thinks it is important to limit information. Stephan responded t...
...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_list = sorted(original, key=(lambda v: v.attr1, v.attr2)) That gets the job done, but it hardly reaches the standard of executable pseudocode that fits Python's reputation. If they don't like lambda specifically, the operator module offers an alternative that still allows the key function to be defined inline: sorted_list = sorted(original, key=operator.attrgetter(v. 'attr1', 'attr2')) Again, it gets the job done, but even the most generous of readers would not con...
PEP 386 -- Changing the version comparison module in Distutils PEP:386 Title:Changing the version comparison module in Distutils Author:Tarek Ziadé <tarek at ziade.org> Status:Superseded Type:Standards Track Created:04-Jun-2009 Superseded-By:440 Contents Abstract Motivation Requisites and current status Distutils Setuptools Caveats of existing systems The new versioning algorithm NormalizedVersion suggest_normalized_version Roadmap References Acknowledgments Copyright...
...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...
PEP 641 -- Using an underscore in the version portion of Python 3.10 compatibility tags PEP:641 Title:Using an underscore in the version portion of Python 3.10 compatibility tags Author:Brett Cannon <brett at python.org>, Steve Dower <steve.dower at python.org>, Barry Warsaw <barry at python.org> PEP-Delegate:Pablo Galindo <pablogsal at python.org> Discussions-To:https://discuss.python.org/t/pep-641-using-an-underscore-in-the-version-portion-of-python-3-10-compa...
Comparing Option-Parsing Libraries Comparing Option-Parsing Libraries NOTE: this page is present for historical purposes only. The getopt-sig is retired, and Optik was added to the Python standard library (as optparse) in Python 2.3. (It was checked in to Python's CVS tree in November 2002, and first released in July 2003.) Since I proposed Optik for the Python standard library, a number of other option-parsing libraries have come to light. I'm trying to evaluate them by ...
...sorted by topics, along with a short explanation or a reference to the relevant thread on the python-3000 mailing list. If you think you should suggest any of the listed ideas it would be better to just step away from the computer, go outside, and enjoy yourself. Being active outdoors by napping in a nice patch of grass is more productive than bringing up a beating-a-dead-horse idea and having people tell you how dead the idea is. Consider yourself warned. Core language Python 3000 will not...
PEP 359 -- The "make" Statement PEP:359 Title:The "make" Statement Author:Steven Bethard <steven.bethard at gmail.com> Status:Withdrawn Type:Standards Track Created:05-Apr-2006 Python-Version:2.6 Post-History:05-Apr-2006, 06-Apr-2006, 13-Apr-2006 Contents Abstract Withdrawal Notice Motivation Example: simple namespaces Example: GUI objects Example: custom descriptors Example: property namespaces Example: interfaces Specification Open Issues Keyword The make-s...
PEP 3002 -- Procedure for Backwards-Incompatible Changes PEP:3002 Title:Procedure for Backwards-Incompatible Changes Author:Steven Bethard <steven.bethard at gmail.com> Status:Final Type:Process Created:27-Mar-2006 Post-History:27-Mar-2006, 13-Apr-2006 Contents Abstract Rationale Python Enhancement Proposals Identifying Problematic Code References Copyright Abstract This PEP describes the procedure for changes to Python that are backwards-incompatible between the Pytho...
...sorted according to the numeric value of the given epoch. If no epoch segment is present, the implicit numeric value is 0. The release segment of version identifiers MUST be sorted in the same order as Python's tuple sorting when the normalized release segment is parsed as follows: tuple(map(int, release_segment.split("."))) All release segments involved in the comparison MUST be converted to a consistent length by padding shorter segments with zeros as needed. Within a numeric release (1.0, 2...
...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...
Python Software Foundation: Minutes of Board of Directors Meeting (December 10, 2002) The Python Software Foundation Minutes of Regular Meeting of the Board of Directors December 10, 2002. A regular meeting of the Python Software Foundation (the "PSF") Board of Directors was held over Internet Relay Chat at 13:02 PM PCT. Guido van Rossum, president of the Foundation and chairman of the Board, presided at the meeting. 1. Attendance The following members of the Board of Directors were pr...
Bugs in Python 2.3.5 IDLE now executes code in a separate process. To communicate between the main process and executing processes, IDLE opens a socket to 127.0.0.1 (the local machine). Some firewalls running on Windows machines interfere with this and can cause either silent failures or erroneous popup windows from the firewall. This problem only occurs if you run a firewall on the same machine as IDLE. Build bugs Some platforms require some tinkering to get a clean build of Python. So...