Friday, February 1, 2019

Concat Dictionary

  • Problem Description

    Write a program to concat two dictionaries display the appended dictionary in the output.


    Input:

    1. Get the key and the corresponding value 

    Output:
    1. Display the first dictionary
    2. Display the second dictionary
    3.Display the concatenated dictionary

    Refer sample input and output for formatting specification. 

    All float values are displayed correct to 2 decimal places. 

    All text in bold corresponds to input and the rest corresponds to output
  • CODING ARENA
  • d1={}
    d2={}
    a=int(input())
    b=int(input())
    c=int(input())
    d=int(input())
    print("First Dictionary")
    d1.update({a:b})
    d2.update({c:d})
    print(d1)
    print("Second Dictionary")
    print(d2)
    print("Concatenated dictionary is")
    if(b>d):
        d2.update(d1)
        print(d2)
    else:
        d1.update(d2)
        print(d1)
  • Test Case 1

    Input (stdin)
    12
    
    144
    
    13
    
    169
    
    
    Expected Output
    First Dictionary
    
    {12: 144}
    
    Second Dictionary
    
    {13: 169}
    
    Concatenated dictionary is
    
    {12: 144, 13: 169}
  • Test Case 2

    Input (stdin)
    81
    
    9
    
    64
    
    8
    
    
    Expected Output
    First Dictionary
    
    {81: 9}
    
    Second Dictionary
    
    {64: 8}
    
    Concatenated dictionary is
    
    {64: 8, 81: 9}

No comments:

Post a Comment