gpt4 book ai didi

python - 在 OrderedDict 中如何按特定属性排序?

转载 作者:行者123 更新时间:2023-11-28 20:41:05 27 4
gpt4 key购买 nike

<分区>

我正在尝试通过执行以下操作对以下 OrderedDict 进行排序-->

>>> from collections import OrderedDict
>>> d = OrderedDict([(4995L, [{'isbn_13': u'9788131805923', 'book_quantity': 49L, 'seller_book_id': 4995L, 'book_id': 4995L, 'title': u'Industrial Automation and Robotics', 'selling_price': 292.0, 'id': 4995L, 'condition': 'New Book'}]), (6657L, [{'isbn_13': u'9788122425925', 'book_quantity': 49L, 'seller_book_id': 6657L, 'book_id': 6657L, 'title': u'A Textbook of Agricultural Statistics', 'selling_price': 243.0, 'id': 6657L, 'condition': 'New Book'}]), (6137L, [{'isbn_13': u'9788122425727\n', 'book_quantity': 50L, 'seller_book_id': 6137L, 'book_id': 6137L, 'title': u'A Guide to Corporate Governance', 'selling_price': 247.0, 'id': 6137L, 'condition': 'New Book'}]), (6260L, [{'isbn_13': u'9788122414394\n', 'book_quantity': 50L, 'seller_book_id': 6260L, 'book_id': 6260L, 'title': u'Management Accounting \n', 'selling_price': 269.0, 'id': 6260L, 'condition': 'New Book'}])])


>>> OrderedDict(sorted(d.items(), key=lambda item: item[1][0]['selling_price']))

通过 selling_price 属性。但我做不到。

我尝试应用此 How to sort OrderedDict of OrderedDict? 中讨论的概念对于普通的 OrderedDict 但它不起作用。有人可以帮帮我吗?时间差

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com