相关疑难解决方法(0)

Python:List vs Dict查找表

我有大约1000万个值,我需要放在某种类型的查找表中,所以我想知道哪个列表字典更有效?

我知道你可以做两件事:

if something in dict_of_stuff:
    pass
Run Code Online (Sandbox Code Playgroud)

if something in list_of_stuff:
    pass
Run Code Online (Sandbox Code Playgroud)

我的想法是dict会更快更有效率.

谢谢你的帮助.

编辑1
关于我正在尝试做什么的更多信息. 欧拉问题92.我正在查找表,看看计算出的值是否已经准备就绪.

编辑2
查找效率.

编辑3
没有与值相关的值...那么一会更好吗?

python performance

158
推荐指数
7
解决办法
14万
查看次数

在具有显式键值的对象列表中查找元素

我在python中有一个对象列表:

accounts = [
    {
        'id': 1,
        'title': 'Example Account 1'
    },
    {
        'id': 2,
        'title': 'Gow to get this one?'
    },
    {
        'id': 3,
        'title': 'Example Account 3'
    },
]
Run Code Online (Sandbox Code Playgroud)

我需要获得id = 2的对象.

当我只知道对象属性的值时,如何从此列表中选择适当的对象?

python types python-2.7

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×2

performance ×1

python-2.7 ×1

types ×1