I have a hashmap like so:
results[tweet_id] = {"score" : float(dot(query,doc) / (norm(query) * norm(doc))), "tweet" : tweet}
What I'd like to do is to sort results by the innser "score" key. I don't know how possible this is, I saw many sorting tutorials but they were for simple (not nested) data structures.
>>> results=[{"s":1,"score":100},{"s":2,"score":101},{"s":3,"score":99},{"s":4,"score":1},{"s":5,"score":1000}]
>>> from operator import itemgetter
>>> sorted(results, key=itemgetter("score"))
[{'s': 4, 'score': 1}, {'s': 3, 'score': 99}, {'s': 1, 'score': 100}, {'s': 2, 'score': 101}, {'s': 5, 'score': 1000}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With