0

In Python 3 when I had to merge two dicts I usually did something like this -

payload = {'key':'value'} 
another_payload = {'another_key':'another_val'}
final_payload = {**payload, **another_payload}

However, now when I do the same in Python 2.7 it throws a Syntax Error. Does Python2 not support it? If it supports how to do the above?

abi24m
  • 161
  • 1
  • 1
  • 5

1 Answers1

0

This works, if it suits you:

dicts = [payload, another_payload]
final_payload = {k: v for d in dicts for k, v in d.items()}
zipa
  • 27,316
  • 6
  • 40
  • 58