PYTHON LAB SESSION 2
1. Write a Python Program to find the maximum occurred word from a dictionary.
Hint: Occurrence will be dependent on lexicography.
Sample Input: names = {“john”, “johnny”, “jackie”, “johnny”, “john”,
“jackie”,“jamie”, “jamie”, “john”, “johnny”, “jamie”, “johnny”,“john”};
Sample Output: John
John and Johnny get maximum occurrence. Since John is alphabetically smaller,
Output is John.
2. Write a Python Program to find the mirror characters from nth position to the
length of the input string.
Hint: In Mirror operation, change ‘a’ to ‘z’, ‘b’ to ‘y’, ‘c’ to ‘x’ and likewise.
Sample Input: string: “abcd”, length = 4
Sample Output: abcw
Sample Input: string: “abcd”, length = 2
Sample Output: ayxw
3. Write a Python Program to create a list of tuples from given list having number
and its cube in each tuple.
Hint: List of Tuples in output having first element as the number it self and
second element as the cube of first element.
Sample Input: list1 = [1, 2, 3]
Sample Output: tup1 = [(1, 1), (2, 8), (3, 27)]
Sample Input: list2 = [5, 6, 7]
Sample Output: tup2 = [(5, 125), (6, 216), (7, 343)]
4. Write a Python Program to sort a list of tuples by second item.
Sample Input: [(‘a’, 56), (‘z’, 8), (‘d’, 78), (‘m’, 6)]
Sample Output: [(‘m’, 6), (‘z’, 8), (‘a’, 56), (‘d’, 78)]
Sample Input: [(‘343’, 5), (‘156’, 90), (‘234’, 24), (‘901’, 3), (‘78’, 78)]
Sample Output: [(‘901’, 3), (‘343’, 5), (‘234’, 24), (‘78’, 78), (‘156’, 90)]
5. Write a Python Program to get sum of list as tuple attribute.
Sample Input: [(‘k1’, [3, 4, 5]), (‘k2’, [1, 4, 2]), (‘k3’, [9, 3, 8])]
Sample Output: [(‘k1’, 12), (‘k2’, 7), (‘k3’, 20)]
6. Write a Python Program to remove strings from tuple.
Sample Input: [(‘Hello’, 1, 2), (‘For’, 4, ‘Python’), (45, ‘World’)]
Sample Output: [(1, 2), (4, ), (45, )]