无法转换字典更新序列元素

2024-09-29 00:16:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用pythonmap函数通过id获取用户,但我有这个错误 如何修复它

enter image description here


Tags: 函数用户id错误pythonmap
1条回答
网友
1楼 · 发布于 2024-09-29 00:16:27
  • 此处的lambda表达式返回布尔值True或False
  • map函数返回一个映射对象,该对象在转换为列表时。 结果[False, False, False]
  • 您无法将其转换为字典,因此会出现错误
  • id()也是一个内置函数,不要将其用作参数

如果op试图通过id获取用户对象,我建议您使用此函数

def get(search_key, users):
    for user in users:
        if int(user['id']) == search_key:
            return user

get(7, users)

相关问题 更多 >