Dictionary merging in Hy

152 Views Asked by At

If I have two dictionaries, and want to merge them with preference to the latter regarding conflicting keys, I would do in Python:

In [1]: x = {'a': 1, 'b': 2}

In [2]: y = {'b': 3, 'c': 4}

In [3]: {**x, **y}
Out[3]: {'a': 1, 'b': 3, 'c': 4}

How can I write this expression in Hy's syntax?

1

There are 1 best solutions below

0
On BEST ANSWER

The dictionary-unpacking operator is unpack-mapping, or #** for short.

=> (setv x {"a" 1  "b" 2})
=> (setv y {"b" 3  "c" 4})
=> {#** x  #** y}
{"a" 1  "b" 3  "c" 4}