Getting a list of values from a list of dict in python: Without using list comprehension -
i have list of dict example,
[{'id': 1l, 'name': u'library'}, {'id': 2l, 'name': u'arts'}, {'id': 3l, 'name': u'sports'}]
now, have retrieve following list dict without using list comprehension
[u'library', u'arts', u'sports']
is there way achieve in python? saw many similar questions, answers using list comprehension.
any suggestion appreciated. in advance.
you use itemgetter
:
from operator import itemgetter categories = map(itemgetter('name'), things)
but list comprehension too. what's wrong list comprehensions?
Comments
Post a Comment