Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

ASSIGNMENT 02

CS14950
Instructions:
1. This paper has 4 questions. Attempt all.
2. You must submit individual code files for every question. Your files should be
named as follow:
<Your_Roll_No.>_CS14950_<AsgnNo>_<Question_Number>.py
For example: 21PY124_CS14950_Asgn02_Q2a.py
3. You must submit the code file in the following link:
www.CS14950_A1.com

Question 01:[5]
Given a string S of N characters, print a dictionary that stores each
character as the key and the value of each key is the number of times it
appears in the string S.
Sample:
Input: ‘abdbcdbabdcbd’
Output: {‘a’:2,’b’:5,’c’:2,’d’:4}
Constraint:0<N<104
Question 02:[7]
Given a dictionary invert it.
Sample:
Input: {‘a’:2,’b’:5,’c’:3,’d’:4}
Output: {2:’a’,3:’c’,4:’d’,5:’b’}
Input: {‘a’:2,’b’:5,’c’:3,’d’:5}
Output: {2:’a’,3:’c’, 5:’bd’}
Input: {‘a’:2,’b’:5,’c’:3,’d’:5,’e’:20,’f’:20,’g’:5}
Output: {2:’a’,3:’c’, 5:’bdg’,20:’ef’}
Question 03:[6+2]
a. Given two lists, print their intersection.
Sample:
Input:
[1,5,6,8,9,7,25,62,8,3],[4,8,5,9,62,75,86,32]
Output:
[ 62,8,5,9]
(order doesn’t matter)(don’t use in keyword)
b. Solve the above problem but the order of output must be the same as
they appear in list1. For eg, [5,8,9,62]

You might also like