Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You stated two quite different wants:</p> <ol> <li>"What I want to do is sort a dictionary of lists ..."</li> <li>"I want to be able to iterate through the dictionary in order of ..."</li> </ol> <p>The first of those is by definition impossible -- to sort something implies a rearrangement in some order. Python dictionaries are inherently unordered. The second would be vaguely possible but extremely unlikely to be implemented.</p> <p>What you can do is</p> <ol> <li>Take a copy of the dictionary contents (which will be quite unordered)</li> <li>Sort that</li> <li>Iterate over the sorted results -- and you already have two solutions for that. By the way, the solution that uses "key" instead of "cmp" is better; see <a href="http://docs.python.org/library/functions.html#sorted" rel="nofollow noreferrer">sorted</a></li> </ol> <p>"the third item in the list" smells like "the third item in a tuple" to me, and "e[1][2]" just smells :-) ... you may like to investigate using named tuples instead of lists; see <a href="http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields" rel="nofollow noreferrer">named tuple factory</a></p> <p>If you are going to be doing extract/sort/process often on large data sets, you might like to consider something like this, using the Python-supplied sqlite3 module:</p> <pre><code>create table ex_dict (k text primary key, v0 int, v1 int, v2 int); insert into ex_dict values('item1', 7, 1, 9); -- etc etc select * from ex_dict order by v2; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload