1

I have the following line of code

allGains = { **stringGains, **wordGains }

where stringGains and wordGains are two dictionaries I want to merge. The code is fine and runs ok, but visual studio flags a series of errors starting with unexpected token '**'. I can ignore the error, but having to click through the "do you want to run despite errors" window gets on my nerves, and it might lead me to miss other errors.

Does anyone know what VS does not like this syntax and whether there is anything I can do about it?

PScr
  • 449
  • 2
  • 11

1 Answers1

1

I am not sure you need to do that. Native functionality should let you just update:

In [15]: stringGains = {'a':'b', 'c':'d'}
In [16]: wordGains = {'hello':'world'}
In [17]: stringGains.update(wordGains)
In [19]: stringGains
Out[19]: {'a': 'b', 'c': 'd', 'hello': 'world'}

Explain of double asterisk: What does ** (double star) and * (star) do for parameters?

Community
  • 1
  • 1
Kelvin
  • 1,357
  • 2
  • 11
  • 22
  • Yes, I could re-write it as you suggest. And I might, just to avoid the error flags. I was following a suggestion from http://stackoverflow.com/questions/38987/how-to-merge-two-python-dictionaries-in-a-single-expression and http://treyhunner.com/2016/02/how-to-merge-dictionaries-in-python/ and just liked the syntax. – PScr Dec 16 '16 at 22:13