Menu Close

Check the key

Write a program to check whether the given key is present in the dictionary.

If the key is present then display the value of the entered key and if the key is not present then display the appropriate message.

Input:
1.Get two dictionaries key-value elements
2. Get the key value to be searched

Output:
1. Display the first dictionary
2. Display the second dictionary
3. Display the concatenated dictionary
4. Display whether the key is present or nor and the respective value of the key.

Refer sample input and output for formatting specification.

INPUT:
81
9
64
8
81

OUTPUT:
First Dictionary: {81: 9}
Second Dictionary: {64: 8}
Concatenated dictionary is  {81: 9, 64: 8}
Key is present and value of the key is 9
d1={}
a=int(input())
b=int(input())
d1[a]=b

d2={}
c=int(input())
d=int(input())
d2[c]=d

print('First Dictionary: ',d1)
print('Second Dictionary: ',d2)
d1.update(d2)
print('Concatenated dictionary is ', d1)
val=int(input("\nEnter Key: "))
c=0
for k,v in d1.items():
    if k==val:
        c=c+1
        print("Key is present and value of the key is ",v)
if c==0:
    print("Key not present")


OUTPUT_1:
81
9
64
8
First Dictionary:  {81: 9}
Second Dictionary:  {64: 8}
Concatenated dictionary is  {81: 9,  64: 8}

Enter Key:  81
Key is present and value of the key is  9


OUTPUT_2:
56
65
25
20
First Dictionary:  {56: 65}
Second Dictionary:  {25: 20}
Concatenated dictionary is  {56: 65,  25: 20}

Enter Key:  25
Key is present and value of the key is  20


OUTPUT_3:
100
101
555
556
First Dictionary:  {100: 101}
Second Dictionary:  {555: 556}
Concatenated dictionary is  {100: 101,  555: 556}

Enter Key:  100
Key is present and value of the key is  101


ILLUSTRATION

Executed using python3

Morae Q!

  1. OS operating system module using path parameter.
  2. Find the smallest and largest integers after sorting using bubble sort.
  3. Find the integer and its number of occurrences.
  4. Algorithm complexity – Big O Notation with Examples.
  5. Linear search.
  6. Map module using series mapping and parallel mapping.
  7. Mapping and Transposing with Map Module.
  8. Map Module/built-in Function.
  9. Linux commands for managing files.
  10. Program which takes two lists and maps two lists into a dictionary.
  11. Splitting strings and substituting using regular expressions regex.
  12. Basics of regular expression Regex.
  13. Find the square value of the dictionary.
  14. Check whether the given key is present in the dictionary.
  15. Matching an expression only in specific places using regular expressions.
  16. Escaping special characters using regular expressions.
  17. Check the key.
  18. Grouping and sub-grouping using regular expressions.
  19. Generate a Dictionary that Contains Numbers in the Form (x , x*x).
  20. Algorithm complexity Big-Theta, Big-Omega and Big-O Notations.