比方说,我有对象名单:Python:如何查询对象列表?
listt = [{
"CustomerId": "1",
"Date": "2017-02-02",
"Content": "AAAAAAAA",
"Type": 2
},
{
"CustomerId": "2",
"Date": "2017-02-03",
"Content": "BBBBBBBB",
"Type": 1
},
{
"CustomerId": "3",
"Date": "2017-02-01",
"Content": "CCCCCCCCC",
"Type": 1
},
{
"CustomerId": "4",
"Date": "2017-02-12",
"Content": "DDDDDDDDDD",
"Type": 2
}, ]
什么是寻找解决这些的最彻底的方法?
- 最小日期其中Type = 1
=> 2017年2月1日
- 选择内容其中Type = 2和日期= (与第一类型的所有对象中最小日期= 2)
=> AAAAAAAA
我在阅读关于利用lambda和过滤器,但我一直无法取得任何进展。任何人都可以帮忙吗?
你在db上还是仅仅在列表中有这些对象?如果他们在db中,你可以使用ORM进行查询,这将更容易和更有效地检索。 –
数据库中没有它们。 :( – 90abyss