-2

I have two variable a and b assigned some values in a list, merge those values as below

a = [{'test0': '-166.05043999999998'},
 {'test1': '0.39523979999999925'},
 {'test2': '0.8905380999999923'}]

b = [{'test3': '-168.05043999999998'},
 {'test4': '1.39523979999999925'},
 {'test5': '2.8905380999999923'}]

and I want to make it as

  ab = [{'test0': '-166.05043999999998',
 'test1': '0.39523979999999925',
 'test2': '0.8905380999999923',
 'test3': '-168.05043999999998',
 'test4': '1.39523979999999925',
 'test5': '2.8905380999999923'}]
Nikhil
  • 1
  • 1
  • 3

2 Answers2

1

Im not a expert in Python myself but this should work :)

a = [{'test0': '-166.05043999999998'},
 {'test1': '0.39523979999999925'},
 {'test2': '0.8905380999999923'}]

b = [{'test3': '-168.05043999999998'},
 {'test4': '1.39523979999999925'},
 {'test5': '2.8905380999999923'}]

ab = []

for i in a:
    ab.append(i)

for i in b:
    ab.append(i)
0

python

a = [{'test0': '-166.05043999999998'},
     {'test1': '0.39523979999999925'},
     {'test2': '0.8905380999999923'}]
b = [{'test3': '-168.05043999999998'},
    {'test4': '1.39523979999999925'},
    {'test5': '2.8905380999999923'}]
a + b
mrEvgenX
  • 758
  • 8
  • 16
  • 1
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – ZF007 Oct 22 '20 at 10:52
  • My explanation is you can just add the variables you want to merge with – amateur_programmer_i_think Oct 23 '20 at 01:39