简体   繁体   English

TypeError:列表索引必须是整数或切片,而不是 str WITH API

[英]TypeError: list indices must be integers or slices, not str WITH API

result = [{'line': 'johannsasuke@gmail.com:42ab89', 'sources': ['Taringa.net'], 'last_breach': '2017-08'}, {'line': 'johannsasuke@gmail.com:PEIN12345', 'sources': ['Evony.com'], 'last_breach': '2016-07'}, {'line': 'johannsasuke@gmail.com:sasuke12345', 'sources': ['Animoto.com', 'Collection 1', 'xSplit'], 'last_breach': '2019-01'}, {'line': 'johannsasuke@gmail.com', 'sources': ['xSplit'], 'last_breach': '2013-11', 'email_only': 1}]

for x in result:

   if result['email_only']==1:

     pass

   else:

     print(result['line'])

I'm trying to print the combos that are released with this api but am getting TypeError: list indices must be integers or slices, not str.我正在尝试打印与此 api 一起发布的组合,但出现 TypeError:列表索引必须是整数或切片,而不是 str。 Please help!请帮忙!

result is a list, so you probably meant x , as this is your item: result是一个列表,因此您的意思可能是x ,因为这是您的项目:

for x in result:
    if x.get("email_only") == 1:
        continue
    print(x["line"])

Prints:印刷:

johannsasuke@gmail.com:42ab89
johannsasuke@gmail.com:PEIN12345
johannsasuke@gmail.com:sasuke12345

NOTE: I used x.get() , because it returns None if key email_only doesn't exist in the dictionary (not throwing exception).注意:我使用x.get() ,因为如果字典中不存在密钥email_only (不抛出异常),它会返回None

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

相关问题 “TypeError:list indices必须是整数或切片,而不是str” - “TypeError: list indices must be integers or slices, not str” TypeError:列表索引必须是整数或切片,而不是 str - TypeError: List indices must be integers or slices and not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str “TypeError:列表索引必须是整数或切片,而不是 str” - "TypeError: list indices must be integers or slices, not str" TypeError:列表索引必须是整数或切片而不是 str - TypeError: list indices must be integers or slices not str Python3-TypeError:列表索引必须是整数或切片,而不是str-List - Python3 - TypeError: list indices must be integers or slices, not str - List 使用 Python TypeError 解析 JSON:列表索引必须是整数或切片,而不是 str - Parsing JSON with Python TypeError: list indices must be integers or slices, not str 如何解决“类型错误:列表索引必须是整数或切片,而不是 str” - How to solve "TypeError: list indices must be integers or slices, not str" Scrapy TypeError:列表索引必须是整数或切片,而不是 str - Scrapy TypeError: list indices must be integers or slices, not str 遍历字典:类型错误:列表索引必须是整数或切片,而不是 str - Iterating through a dictionary: TypeError: list indices must be integers or slices, not str
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM