In List of Dicts, find min() value of a common Dict field

后端 未结 5 1765
说谎
说谎 2020-11-27 12:00

I have a list of dictionaries like so:

[{\'price\': 99, \'barcode\': \'2342355\'}, {\'price\': 88, \'barcode\': \'2345566\'}]

I want to fin

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 12:26

    One answer would be mapping your dicts to the value of interest inside a generator expression, and then applying the built-ins min and max.

    myMax = max(d['price'] for d in myList)
    myMin = min(d['price'] for d in myList)
    

提交回复
热议问题