简体   繁体   English

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

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

say I have a dictionary ie 说我有字典,即

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

when I run the code below, it gives the error: argument of type bool is not iterable . 当我运行下面的代码时,出现错误: argument of type bool is not iterable I'm really stuck on this and would appreciate a solution. 我真的很坚持,不胜感激。 The code takes two inputs, the dict and a user. 该代码接受两个输入,即dict和一个用户。 It's supposed to check if user is in dict - if it is, return the first element in the value. 应该检查用户是否在字典中-如果存在,则返回值中的第一个元素。 otherwise, return None. 否则,返回None。

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

problem is 问题是

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

you have to give it as 你必须给它作为

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

dict with list as element 用列表作为元素的字典

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

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