About 346,000 results
Open links in new tab
  1. python - How do I sort a dictionary by value? - Stack Overflow

    Mar 5, 2009 · I have a dictionary of values read from two fields in a database: a string field and a numeric field. The string field is unique, so that is the key of the dictionary. I can sort on the keys, but ...

  2. How can I sort a list of dictionaries by a value of the dictionary in ...

    Python has supported the key= for .sort since 2.4, that is year 2004, it does the Schwartzian transform within the sorting code, in C; thus this method is useful only on Pythons 2.0-2.3. all of which are more …

  3. python - How do I sort a dictionary by key? - Stack Overflow

    Jan 26, 2017 · From python 3.7.4 manual: "Performing list (d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order". So insertion order is something which is preserved and we …

  4. python - Sort dictionary of dictionaries by value - Stack Overflow

    Similar to the post you linked, this uses the key function of sorted to provide a custom sort order. iteritems() returns a (key, value) tuple, so that gets passed into lambda (x, y): y['position'], where …

  5. Sort Dict by Values in Python 3.6+ - Stack Overflow

    Sep 3, 2018 · 5 By default, the dictionary is sorted based on keys, but the sorted function takes a function as a parameter using which you can alter the behaviour for program.

  6. dictionary - sort dict by value python - Stack Overflow

    7 I also think it is important to note that Python dict object type is a hash table (more on this here), and thus is not capable of being sorted without converting its keys/values to lists. What this allows is dict …

  7. Python 3 sort a dict by its values - Stack Overflow

    Oct 5, 2015 · To sort a dictionary and keep it functioning as a dictionary afterwards, you could use OrderedDict from the standard library. If that's not what you need, then I encourage you to reconsider …

  8. python dictionary sorting in descending order based on values

    I want to sort this dictionary d based on value of sub key key3 in descending order. See below:

  9. python - Sort dict by highest value? - Stack Overflow

    In this case it's a lambda that fetches the corresponding dict value, but it can be pretty much anything. For example, you could use operator.itemgetter(1) or myDict.get as shown by other answers, or any …

  10. Fastest way to sort a python 3.7+ dictionary - Stack Overflow

    Now that the insertion order of Python dictionaries is guaranteed starting in Python 3.7 (and in CPython 3.6), what is the best/fastest way to sort a dictionary - both by value and by key? The most