S
S
Sergey Grigorov2018-06-25 00:50:26
Python
Sergey Grigorov, 2018-06-25 00:50:26

How to sort the results in a dictionary?

Hello again.
There is a result in the form:

{
    "doc1": [
        {
            "word1": [1,0,0.2]
        },
        {
            "word2": [1,10,0.2]
        }
    ],
    "doc2": [
        {
            "word1": [2,5,0.3]
        },
        {
            "word2": [2,8,0.3]
        }
    ]
}

To put it simply:
doc1:
word1: occurs 1 time, entry point 0, percentage of document: 20%
word2: occurs 1 time, entry point 10, percentage of document 20%
doc2:
word1: occurs 2 times, entry point 5, percentage of document 30%
word1: occurs 2 times, occurrence point 8, percentage of the document 30%
It is necessary to sort the results in such a way that they go in descending order - the lower the number of occurrences, entry point and percentage, the higher the result in the output.
Question: how can this kind of sorting be implemented using Python?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question