Reputation: 25554
I'm new to Python. I have this code using Feedparser:
import feedparser
d = feedparser.parse('http://pplware.sapo.pt/feed/')
i = range(10)
for i in range(10):
updates = [{"url": d.entries[i].link, "msg": d.entries[i].summary + ", "}]
My question.
How can I add to the variable "updates" the 10 entries?
Best Regards,
Upvotes: 0
Views: 2426
Reputation:
d = feedparser.parse('http://pplware.sapo.pt/feed/')
for item in d.entries[:10]:
print item
Extracting information from 'item' and adding it to a list or dict is basic usage of Python lists and dicts (please read the tutorial in this case - we must not teach very basic usage of lists and dicts here).
Upvotes: 0
Reputation: 41030
import feedparser
d = feedparser.parse('http://pplware.sapo.pt/feed/')
updates = []
for i in range(10):
updates.append({"url": d.entries[i].link, "msg": d.entries[i].summary + ", "})
In your for loop, you append the dictionnary result to the updates list. 'updates' contains 10 elements after the for loop. One for each entry.
EDIT:
However, the code provided by RestRisiko is really more beautiful ;-)
Upvotes: 1