I’m new to Python and come from a Java background. I’d like to know the most Pythonic way of writing this code:
entry_list = []
for entry in feed.entry:
entry_list.append(entry.title.text)
Basically for each element in the feed, I’d like to append that element’s title to a list.
I don’t know if I should use a map() or lambda function or what…
Thanks
most pythonic code I can think of:
This is a list comprehension which will construct a new list out of the elements in feed.entry.title.text.
To append you will need to do:
As a side note, when doing extend operations, the normally fast generator expression is much slower than a list comprehension.