0

I am curious why this works

m1, m2 = {'a': 1, 'b': 2}, {'a1': 11, 'b': 2}
{**m1, **m2}

while this does not:

{**m for m in (m1, m2)}

Wouldn't it make sense for dict comprehension to 'understand' the new syntax?

Edit (hopefully, temporary): in response to 'possible duplicate' flag. I am aware of that other question. I hope it is clear that I am not asking how to merge dictionaries.

martineau
  • 119,623
  • 25
  • 170
  • 301
user443854
  • 7,096
  • 13
  • 48
  • 63

1 Answers1

2

You can read about the justification in https://www.python.org/dev/peps/pep-0448/ yourself.

From what I gather, the concerns were about clarity and confusion with function call argument expressions. As it is with these matters of taste the answer might not be as satisfying as one wishes for.

deets
  • 6,285
  • 29
  • 28
  • They don't give the justification, but it is good to see they considered it: "This PEP does not include unpacking operators inside list, set and dictionary comprehensions although this has not been ruled out for future proposals." – user443854 Aug 30 '18 at 16:15
  • Oh. Good for you reading it even bette than me ;8 – deets Aug 30 '18 at 17:54