• Python question of the day

    In python 3.8 two dictionaries, d1 and d2, were created - d1 = {'p': 1, 'q': 2}; d2 = {'q': 3, 'r': 4}. Which of the following code snippet would NOT merge d1 and d2 into a new dictionary, d3, that will have {'q': 2, 'r': 4, 'p': 1} as its data.
     d3 = d2 | d1
     d3 = {**d2, **d1}
     d3 = d2.copy(); d3.update(d1)
     d3 = dict(list(d2.items()) + list(d1.items()))
    Explanation:
    The code snippet, d3 = d2 | d1 works in version 3.9 or later versions only


    Top 100 python interview questions:






datai analytics