robotframework

How do I merge two dictionaries together in Robot Framework?


Suppose I have these two dictionaries:

&{dictOne} =  Create Dictionary  key             value             anotherkey  anothervalue
&{dictTwo} =  Create Dictionary  yetanother_key  yetanother_value  finalkey    finalvalue

How could I merge those two dictionaries together into a third one that has both dictOne's and dictTwo's key-value pairs?

{
    'key': 'value',
    'anotherkey': 'anothervalue',
    'yetanother_key': 'yetanother_value',
    'finalkey': 'finalvalue'
}

Solution

  • You use Create Dictionary keyword:

        ${dictOne}  Create Dictionary  key             value             anotherkey  anothervalue
        ${dictTwo}  Create Dictionary  yetanother_key  yetanother_value  finalkey    finalvalue
        ${merged}    Create Dictionary    &{dictOne}    &{dictTwo}
        Log Dictionary    ${merged}