繁体   English   中英

TypeError:“ bool”类型的参数不可迭代

[英]TypeError: argument of type 'bool' is not iterable

说我有字典,即

dict = {'tommy' = '[[], []]'}

当我运行下面的代码时,出现错误: argument of type bool is not iterable 我真的很坚持,不胜感激。 该代码接受两个输入,即dict和一个用户。 应该检查用户是否在字典中-如果存在,则返回值中的第一个元素。 否则,返回None。

def get_stuff(dict, user):
    if user in dict:
         return dict[user][0]
    return None

问题是

dict = {'tommy' = '[[], []]'}

你必须给它作为

dict = {'tommy' = [[], []]}

用列表作为元素的字典

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM