问题:如何读取由对象组成的列表中的最小值?
如何读取“room_options”列表中“price”参数的最小值,其中包含列表的 n 个元素。每个列表项都是 Room 类的一个实例:
room_options: (list)
[0] Room
[1] Room
[2] Room
[3] Room
...
[n] Room
Room:
price=700
currency="PLN"
type="Twin Room"
dining=True
我想使用以下语句读取最小值:
min(unknown_statement)
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:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
min(room_options, key=lambda x: x.price)
min(room_options, key=lambda x: x.price)
编辑:参见评论
EDIT: see comment