Created
March 25, 2013 23:00
-
-
Save riywo/5241652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> dict(map(lambda x: [x["k"], x], [{"k":"1", "v":1}, {"k":"2","v":2}])) | |
{'1': {'k': '1', 'v': 1}, '2': {'k': '2', 'v': 2}} |
Python 2.7 以降なら辞書内包表記も使えます
>>> {x.pop("k"): x for x in [{"k":"1", "v":1}, {"k":"2","v":2}]}
{'1': {'v': 1}, '2': {'v': 2}}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
map + lambda よりもリスト内包の方が良いです