Menu Close

Program which takes two lists and maps two lists into a dictionary.

Write the python program which takes two lists and maps two lists into a dictionary.

INPUT
3         # size of list
1 2 3     # list 1
1 4 9     # list 2

OUTPUT
The dictionary is:
{1: 1, 2: 4, 3: 9}
N = int(input("Size: "))
L1 = list(map(int,input("List1: ").split(" ")))
L2 = list(map(int,input("List2: ").split(" ")))
dict = {}
for i in range(N):
    dict[int(L1[i])]=int(L2[i])
print("The dictionary is: ",dict)

INPUT_1:
Size:  3
List1:  1  2  3
List2:  1  4  9

OUTPUT:
The dictionary is:  {1: 1,  2: 4,  3: 9}


INPUT_2:
Size:  5
List1:  8  6  5  9  22
List2:  20  21  22  23  25

OUTPUT:
The dictionary is:  {8: 20,  6: 21,  5: 22,  9: 23,  22: 25}


INPUT_3:
Size:  4
List1:  4  8  16  20
List2:  5  10  15  20

OUTPUT:
The dictionary is: {4: 5,  8: 10,  16: 15,  20: 20}


ILLUSTRATION

Executed using python 3 Linux terminal

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.