Friday, February 1, 2019

Delete Keys

  • Problem Description

    Write a program to delete the keys in the dictionaries

    Input:

    1.Get Four dictionaries key-value elements
    2. The Key to be deleted

    Output:
    1. Display the first dictionary
    2. Display the second dictionary
    3. Display the third dictionary
    4. Display the fourth dictionary
    5. Display the concatenated dictionary
    6. Display the updated dictionaries

    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
  • a=int(input())
    b=int(input())
    c=int(input())
    d=int(input())
    e=int(input())
    f=int(input())
    g=int(input())
    h=int(input())
    d1={}
    d2={}
    d3={}
    d4={}
    key=int(input())
    d1.update({a:b})
    d2.update({c:d})
    d3.update({e:f})
    d4.update({g:h})
    print("First Dictionary")
    print(d1)
    print("Second Dictionary")
    print(d2)
    print("Third Dictionary")
    print(d3)
    print("Fourth Dictionary")
    print(d4)
    d1.update(d2)
    d1.update(d3)
    d1.update(d4)
    print("Concatenated dictionary is")
    print(d1)
    if key in d1:
        print("Updated dictionary")
    if key in d1:
    del(d1[key])
    print(d1)
    else:
        print("Key not found")
  • Test Case 1

    Input (stdin)
    25
    
    520
    
    23
    
    320
    
    45
    
    540
    
    12
    
    210
    
    25
    
    
    Expected Output
    First Dictionary
    
    {25: 520}
    
    Second Dictionary
    
    {23: 320}
    
    Third Dictionary
    
    {45: 540}
    
    Fourth Dictionary
    
    {12: 210}
    
    Concatenated dictionary is
    
    {25: 520, 23: 320, 45: 540, 12: 210}
    
    Updated dictionary
    
    {23: 320, 45: 540, 12: 210}
  • Test Case 2

    Input (stdin)
    25
    
    520
    
    23
    
    320
    
    45
    
    540
    
    12
    
    210
    
    14
    
    
    Expected Output
    First Dictionary
    
    {25: 520}
    
    Second Dictionary
    
    {23: 320}
    
    Third Dictionary
    
    {45: 540}
    
    Fourth Dictionary
    
    {12: 210}
    
    Concatenated dictionary is
    
    {25: 520, 23: 320, 45: 540, 12: 210}
    
    Key not found

No comments:

Post a Comment