Combine dictionary keys

Hi, is there a way to combine these keys?

@vanman ,

zip function is good


# πŸ“Œ combine via zip

OUT = [k for k in zip(IN[0],IN[1])]

Hi,

try to merge dictionaries into one

examples

2 Likes

Can be done with out of the box nodes as well.

  • A Dictionary.Keys node to get all the keys from each dictionary.
  • A Dictionary.ValueAtKey node to get the value associated with each key in the dictionary.
  • Two List.Flatten nodes to remove the extra list structure.
  • And a Dictionary.ByKeysValues node to build the combined dictionary.

Things get more difficult when each key isn’t unique, but if you want to append to the list that can be solved by using a List.GroupByKey node and another flatten node with proper lacing and list levels on both.

2 Likes

Two ways with OOTB

3 Likes

And python

OUT = {k: v for d in IN[0] for k, v in d.items()}
OUT = dict()
[OUT.update(d) for d in IN[0]]
4 Likes