我有两个列表(即查询集和列表):
PORT
:
filter_perceptions
和另一个清单
<QuerySet [<Perception: Perception #0000001>, <Perception: Perception #0000009>, <Perception: Perception #0000017>, <Perception: Perception #0000018>]>
:
results
我想创建一个包含最后两个列表的新列表。实际上,我想过滤[{u'object': <Perception: Perception #0000018>, u'cols': <generator object items_for_result at 0x7f9264c56780>}, {u'object': <Perception: Perception #0000017>, u'cols': <generator object items_for_result at 0x7f9264c562d0>}, {u'object': <Perception: Perception #0000016>, u'cols': <generator object items_for_result at 0x7f926532bc30>}, {u'object': <Perception: Perception #0000015>, u'cols': <generator object items_for_result at 0x7f9264c178c0>}, {u'object': <Perception: Perception #0000014>, u'cols': <generator object items_for_result at 0x7f9264c17f50>}, {u'object': <Perception: Perception #0000013>, u'cols': <generator object items_for_result at 0x7f9264c17fa0>}, {u'object': <Perception: Perception #0000012>, u'cols': <generator object items_for_result at 0x7f9264c17960>}, {u'object': <Perception: Perception #0000011>, u'cols': <generator object items_for_result at 0x7f92643a3050>}, {u'object': <Perception: Perception #0000010>, u'cols': <generator object items_for_result at 0x7f92643a30a0>}, {u'object': <Perception: Perception #0000009>, u'cols': <generator object items_for_result at 0x7f92643a30f0>}, {u'object': <Perception: Perception #0000008>, u'cols': <generator object items_for_result at 0x7f92643a3140>}, {u'object': <Perception: Perception #0000007>, u'cols': <generator object items_for_result at 0x7f92643a3190>}, {u'object': <Perception: Perception #0000006>, u'cols': <generator object items_for_result at 0x7f92643a31e0>}, {u'object': <Perception: Perception #0000005>, u'cols': <generator object items_for_result at 0x7f92643a3230>}, {u'object': <Perception: Perception #0000004>, u'cols': <generator object items_for_result at 0x7f92643a3280>}, {u'object': <Perception: Perception #0000003>, u'cols': <generator object items_for_result at 0x7f92643a32d0>}, {u'object': <Perception: Perception #0000002>, u'cols': <generator object items_for_result at 0x7f92643a3320>}, {u'object': <Perception: Perception #0000001>, u'cols': <generator object items_for_result at 0x7f92643a3370>}]
,以便它仍然是符合results
感知的列表。谁能知道我们怎么能聪明地做这件事呢?
以下是剩余列表的示例
filter_perceptions
谢谢!
P.S。如果问题不清楚,请告诉我。
答案 0 :(得分:0)
尝试
[r for r in results if r['object'] in filter_perceptions]