-1

I have 3 classes:(I want 4th class to have 3 dicts merged and look like: merged_dicts = {1:1,2:2,3:3,4:4,5:5,6:6,7:7} inside 4th class)

class FIRST(workflow):
    first = {1:1, 2:2, 3:3}
class SECOND(workflow):
    second= {4:4, 5:5, 6:6}
class THIRD(workflow):
    third= {7:7}
class FINAL(FIRST,SECOND,THIRD):
    merged_dicts = ?

Also how to do this if first second and third share same variable name(for example my_dict)

  • 1
    https://stackoverflow.com/questions/37584544/dict-merge-in-a-dict-comprehension I know this post handles a slightly different problem, but maybe your question can be answered with the information in it – py_coffee Mar 07 '22 at 10:32

1 Answers1

2

You can merge multiple dictionaries by using the pipe character merged_dicts = first | second | third or by doing merged_dicts = {**first, **second, **third}. In both cases, the result will be: merged_dicts = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7}

kikarat
  • 21
  • 2