How can the dictionary
class Foo: def __init__(self,value): self.property = value dictionary = {"one":Foo(1), "two":Foo(2)}
be sorted in descending order, by the value of the Foo object's self.property?
Foo
self.property
sorted_dict = {k: v for k, v in sorted(dictionary.items(), key=lambda item: item[1].property)}
2.1m questions
2.1m answers
60 comments
57.0k users