+ 1
Merging dictionaries to a list
I need this: x = {a:1, b:2} y = {c:3, d:4} to become this: z = [{a:1, b:2}, {c:3, d:4}] How do I go about it?
4 Answers
+ 6
You can do this:
z = [ x , y ]
+ 7
The issue is that you need to put quotes around the characters. Otherwise the code will not run. The rest is ok:
x = {'a':1, 'b':2}
y = {'c':3, 'd':4}
z = [x, y]
print(z)
#output:
#[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]
+ 2
What is the problem with
z = ........
You have done it correctly
0
Done. Thanks.