Reputation: 400
I'm iterating over a JSON object, then adding each result I get to an array but for each result that gets added to the array, they array is then cleared then it moves down the list of results.
Here's the code I used to get this issue:
for e in loadedJson['posts']['entities']:
print(e)
titles = []
titles.append(e)
print(titles)
Upvotes: 0
Views: 43
Reputation: 597
Try to move titles outside the loop
titles = []
for e in loadedJson['posts']['entities']:
print(e)
titles.append(e)
print(titles)
Upvotes: 3