【发布时间】:2014-07-06 16:31:17
【问题描述】:
所以我有一个字典列表, 例如:
[{'title':'Green eggs and ham', 'author':'dr seuss'}, {'title':'matilda', 'author':'roald dahl'}]
如果这些字典中存在 malcolmgladwell 的异常值,最好的搜索方法是什么?
我正在考虑蛮力检查每个标题和作者,但我觉得必须有更好的方法。
【问题讨论】:
-
列表是否以任何方式排序?
-
你能改变结构吗?
{author: {title: book, ...}, ...}让它变得微不足道。 -
您需要它们作为字典吗?
set的元组(标题,作者)可能会更快
标签: python list search dictionary