Skip to content

Tag: dictionary

Sort dictionary by the INT value of the value

There are many posts here about sorting dictionaries in Python so I was careful to read them and hope this is not a duplicate: I’m using a dictionary to hold words as keys and the occurrence of the word as value. This leads to a dictionary that could be like: I want to sort them by occurrence (the &#821…

find max , min of values in multidimensional dict

I want to find 1. key with max Load_1min value , 2. key with min Load_1min value , 3. avg value of all the load_min keys for stats. Last one is simple – But 1st two are tough. I tried max function but failed. Answer Use the key argument to min and max: In addition to iterating over the keys,

Intersecting two dictionaries

I am working on a search program over an inverted index. The index itself is a dictionary whose keys are terms and whose values are themselves dictionaries of short documents, with ID numbers as keys and their text content as values. To perform an ‘AND’ search for two terms, I thus need to interse…

What does the == operator actually do on a Python dictionary?

Consider: According to the python doc, you can indeed use the == operator on dictionaries. What is actually happening here? Is Python recursively checking each element of the dictionaries to ensure equality? Is it making sure the keys are identically matched, and the values are also identically matched? Is th…