Issue
What is the pythonic way to convert a list of objects such as
dic = [{'name':'foo', 'age':23}, {'name':'bar', 'age':25}, {'name':'baz', 'age':28}]
to a list of strings like below?
lst = ['foo', 'bar', 'baz']
Solution
Use list comprehension
lst = [k['name'] for k in dic]
Answered By - softwarematter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.