开发者

Problem: How to read a minimum value in the list consisting of objects?

开发者 https://www.devze.com 2023-03-06 02:40 出处:网络
How can I read the minimum value of \"price\" parameter in the \"room_options\" list, with n elements of the list. Each list item is an instance of Room class:

How can I read the minimum value of "price" parameter in the "room_options" list, with n elements of the list. Each list item is an instance of Room class:

开发者_如何学Python
room_options: (list)
   [0] Room
   [1] Room
   [2] Room
   [3] Room
   ...
   [n] Room

Room:
   price=700
   currency="PLN"
   type="Twin Room"
   dining=True

I'd like to read a minimum value with the statement:

min(unknown_statement)


min(room_options, key=lambda x: x.price)


min(room.price for room in rooms)

EDIT: see comment

0

精彩评论

暂无评论...
验证码 换一张
取 消