Objects has been created by a website crawler. In this example, a title and the image file path is stored. The output is as following:
for article in fetcher.fetch():
print(article.title + " | " + article.image)
Polarised modular conglomeration | ./img/1.jpg
Cross-group contextually-based middleware | ./img/2.jpg
De-engineered encompassing structure | ./img/3.jpg
Fully-configurable multi-tasking interface | ./img/4.jpg
Versatile eco-centric core | ./img/5.jpg
Optional maximized utilisation | ./img/6.jpg
Open-architected secondary product | ./img/7.jpg
The goal is to store title as key and image path as value in a dictionary
dict = {}
for dictionary in fetcher.fetch():
dict = {dictionary.title: dictionary.image}
print(dict)
{'Open-architected secondary product': './img/7.jpg'}
Problem: Only the last item is stored in the dictionary. What is wrong with my code?
Thank you
dictevery loop, instead of adding to an existing dictionary