Friday, February 1, 2019

Dictionary Using List

  • Problem Description

    Write a program to get the input of key and value of the element in dictionary.

    Display the key-value pair in the python dictionary format.

    Kindle get the input using List Concept.

    Input:
    1. Size of first list
    2. Elements of first list
    3. Size of second list
    4. Elements of second list

    Output:
    1. The first list elements are keys of the dictionaries
    2. The second list elements are corresponding elements of the dictionaries
  • CODING ARENA
  • x=[]
    y=[]
    d1={}
    a=int(input())
    for i in range(a):
        m=int(input())
        x.append(m)
    b=int(input())
    for i in range(b):
        m=int(input())
        y.append(m)
    for i in range(a):
        d1.update({x[i]:y[i]})
    print(d1)
  • Test Case 1

    Input (stdin)
    2
    
    12
    
    14
    
    2
    
    1212
    
    1414
    
    
    Expected Output
    {12: 1212, 14: 1414}
  • Test Case 2

    Input (stdin)
    2
    
    4
    
    5
    
    2
    
    16
    
    25
    
    
    Expected Output
    {4: 16, 5: 25}

No comments:

Post a Comment