I have a dictionary Retweets containing tweets information. The data structure of a tweet is like this:
[{'retweet_count': 338,
'user': {'description': 'description1.',
'followers_count': 582,
'screen_name': 'screen_name1'}
}
]
I want to take only the screen_name of the user and corresponding description into a new dict. Make this into a dict like this:
{'screen_name1': 'description1',
'screen_name2': 'description2',
'screen_name3': 'description3'
}
Here is my code:
user_list = []
for retweet in Retweets:
user_list.append(retweet["user"]["screen_name"])
final_dict = {key: retweet["user"]["description"] for key in user_list}
print(final_dict)
However, the descriptions of all users are the description of the last user. Like this:
{'screen_name1': 'description3',
'screen_name2': 'description3',
'screen_name3': 'description3'
}
Could anyone help me with this problem? Thank you!