Assuming that your results
is a dict
(because you called it a hashmap, and because I'm guessing that tweet_id
is a dictionary key, not a counter), you need to convert it to a list first in order to be able to sort it. In Python 3:
results = {}
results["1234"] = {"score": 123, "tweet": "Hello"}
results["4321"] = {"score": 321, "tweet": "there"}
results["abcd"] = {"score": 111, "tweet": "sailor!"}
l=[]
for key, value in results.items(): # use .iteritems() in Python 2.x
l.append([key, value])
for item in sorted(l, key=lambda x: x[1]["score"]):
print(item)
will output
['abcd', {'tweet': 'sailor!', 'score': 111}]
['1234', {'tweet': 'Hello', 'score': 123}]
['4321', {'tweet': 'there', 'score': 321}]