Skip to content

Instantly share code, notes, and snippets.

@terashim
Created July 29, 2021 14:27
Show Gist options
  • Save terashim/6f664e9a235d906f8f360bde90c4a553 to your computer and use it in GitHub Desktop.
Save terashim/6f664e9a235d906f8f360bde90c4a553 to your computer and use it in GitHub Desktop.
dict にキーと値を追加する
x = {"a": 1}
{**x, "b": 10}
# {'a': 1, 'b': 10}
lst = [{"a": 1}, {"a": 2}]
list(map(lambda x: {**x, "b": 10}, lst))
# [{'a': 1, 'b': 10}, {'a': 2, 'b': 10}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment