I have a python dictionary in which the keys are usernames in the form of strings and the values are in the form of timedelta
objects. I need to sort the values in order from greatest to least and then access the keys so I can print the top ten values with their usernames in a file.
Once I sort the values using sorted(dictionary.values())
, how do I access the usernames? I already tried dictionary[datetime.timedelta(seconds=84081)]
but I get an attribute error: datetime.datetime’ has no attribute ‘timedelta
. (FYI, I used: from datetime import datetime, timedelta
.)