I like to use higher order functions like map
, I like to use lambda
s, and I prefer to keep my intermediate data representations in lists of dictionaries. Here's a way to map
a list of dictionaries concisely:
>>> favorites = [{'name':'home', 'visited':5}, {'name':'work', 'visited':10}]
>>> map(lambda x: dict(x, **{'visited': x['visited']+1}), favorites)
[{'visited': 6, 'name': 'home'}, {'visited': 11, 'name': 'work'}]