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)}
1.4m articles
1.4m replys
5 comments
57.0k users