by shigemk2

当面は技術的なことしか書かない

Python map/filter

Python map/filter

こんな感じ。

>>> items = [{"id":1,"name":"Alice"}, {"id":2,"name":"Bob"}, {"id":3,"name":"Charles"}]
>>> list(filter(lambda x: x["id"], items))
[{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}, {'id': 3, 'name': 'Charles'}]
>>> list(map(lambda x: x["id"], items))
[1, 2, 3]
>>> list(map(lambda x: x["name"], items))
['Alice', 'Bob', 'Charles']

http://book.pythontips.com/en/latest/map_filter.html