Hi,
I am fairly new to the python language and am trying to sort a nested
Dictionary of a Dictionary which I wish to sort by value. The dictionary
does not have to be restructured as I only need it sorted in this way
for printing purposes.
The following is an example of my Dictionary printed with 'print
dictionary.items()', where '2329513' is the key of the first hash, 'ops'
is the key of the second hash and '50.0' is the value of the second hash
which I would like to sort by:
[('2329513', {'ops': 20.0}), ('2329492', {'ops': '80'}), ('2329490',
{'ops': '50'})]
I hope to sort these first keys by the value of the 'ops' key from
highest to lowest value to give the following result:
[('2329492', {'ops': '80'}), ('2329490', {'ops': '50'}), ('2329513',
{'ops': 20.0})]
Thanks in advance for any help,
Sam. 1 3294
Sam Loxton wrote:
I am fairly new to the python language and am trying to sort a nested
Dictionary of a Dictionary which I wish to sort by value. The dictionary
does not have to be restructured as I only need it sorted in this way
for printing purposes.
The following is an example of my Dictionary printed with 'print
dictionary.items()', where '2329513' is the key of the first hash, 'ops'
is the key of the second hash and '50.0' is the value of the second hash
which I would like to sort by:
[('2329513', {'ops': 20.0}), ('2329492', {'ops': '80'}), ('2329490',
{'ops': '50'})]
I hope to sort these first keys by the value of the 'ops' key from
highest to lowest value to give the following result:
[('2329492', {'ops': '80'}), ('2329490', {'ops': '50'}), ('2329513',
{'ops': 20.0})]
If Dennis' remarks don't apply because you simplified your problem for the
post:
>>d = {'2329513': {'ops': 20.0}, '2329492': {'ops': '80'}, '2329490':
{'ops': '50'}}
>>items = d.items() def key(item):
.... return item[1]["ops"]
....
>>items.sort(key=key, reverse=True) items
[('2329492', {'ops': '80'}), ('2329490', {'ops': '50'}), ('2329513', {'ops':
20.0})]
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: kbass |
last post by:
I am new to Python and I am attempting to retrieve data from a database and
I would like to place this data into a nested dictionary. After placing...
|
by: DelphiBlue |
last post by:
I have a Nested Datagrid that is using a data relations to tie the parent
child datagrids together. All is working well with the display but I am...
|
by: B0nj |
last post by:
I've got a class in which I want to implement a property
that operates like an indexer, for the various colors
associated with the class.
For...
|
by: techiepundit |
last post by:
I'm parsing some data of the form:
OuterName1 InnerName1=5,InnerName2=7,InnerName3=34;
OuterName2 InnerNameX=43,InnerNameY=67,InnerName3=21;...
|
by: Jake Emerson |
last post by:
I'm attempting to build a process that helps me to evaluate the
performance of weather stations. The script below operates on an MS
Access...
|
by: Rich Shepard |
last post by:
I want to code what would be nested "for" loops in C, but I don't know the
most elegant way of doing the same thing in python. So I need to learn...
|
by: hermesbaby |
last post by:
I have a CSV-File which I convert to an array like this:
,
,
,
,
,
]
|
by: qbob |
last post by:
I have data that is essentially tree-like, and to store it/iterate over it I have been using nested dictionaries, eg:
Dictionary<int,...
|
by: =?Utf-8?B?RGF2aWQgTW9ycmlz?= |
last post by:
I am trying to create a nested Dictionary and get an error that seems odd to
me. Here is my declaration:
private IDictionary<Guid,...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
| |