user14737297
user14737297

Reputation:

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

result = [{'line': '[email protected]:42ab89', 'sources': ['Taringa.net'], 'last_breach': '2017-08'}, {'line': '[email protected]:PEIN12345', 'sources': ['Evony.com'], 'last_breach': '2016-07'}, {'line': '[email protected]:sasuke12345', 'sources': ['Animoto.com', 'Collection 1', 'xSplit'], 'last_breach': '2019-01'}, {'line': '[email protected]', '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. Please help!

Upvotes: 0

Views: 132

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195458

result is a list, so you probably meant x, as this is your item:

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

Prints:

[email protected]:42ab89
[email protected]:PEIN12345
[email protected]:sasuke12345

NOTE: I used x.get(), because it returns None if key email_only doesn't exist in the dictionary (not throwing exception).

Upvotes: 0

Related Questions