Unit 4 Question Bank
Unit 4 Question Bank
1. Assume n = [[9, 8, 7], [6, 5, 4], [3, 2, 1]] What is the output for the following. Justify the
answer
print(n[2])
print (n[1][1])
2. Explain negative indexing in List with an example?
3. Write a program to find the sum of elements in list using list comprehension
4. How to change a List into Tuple with one example.
5. Name any four built-in List Methods.
6. Write a program to perform matrix subtraction using nested lists
7. Explain in detail about list comprehension with an example.
8. Explain any 6 python Tuple in-built functions with example for each built-in function.
9. Write the output of the following code snippet.
L=[1,0,3,2]
S=[2,1,’b’,’a’]
L.sort()
print(L)
S.sort()
print(S)
10. T=(‘a’,’b’,’c’). Write a for loop to traverse the elements of a tuple.
11. Create a tuple with single element.
12. Explain List Comprehension(LC) with syntax and using LC write a python code to display
the eligible candidates to vote along with their age in the given list.
Age_list = [20,15,25,10,45]
13. Compare tuple and dictionary suitable examples.
14. Let L1=[101, 102, 100, 105, 106]
Create a list L2 using aliasing L1.
Create a list L3 using cloning L1.
Modify list L2 observe what happens in L1.
Delete elements in L3 with help of slicing operator. Observe what happens in L1.
15. Write a python program to store the details about the number in words in Tuple.
Eg. I/P: 123,
O/P: (“3 Digit”, "one","two”,”three”)
Eg. I/p: 12312,
O/P: (“5 Digit”, “one”,”two”,”three”,”one”,”two”).
16. Write a Python program that takes a list and a value as inputs and prints that value's all
index numbers as a new list. (Input list can also have nested list/s with duplicate values).
17. Differentiate aliasing and cloning in Lists.
18. Write a program to read two lists from the user and find the common elements from both
the lists. If there are no common elements, print the list is empty else print the list of
common elements.
19. Define two lists namely WordList and CharList consisting of list of words and characters
respectively. Develop a program to take the words (from the WordList) containing any
character from the CharList and print them as new list.
Word list : ['apple', 'orange', 'banana', 'fig', 'cherry']
CharList : ['l', 'r']
NewList : ['apple', 'orange', 'cherry']
20. Initialize a m x n matrix and find the transpose of the same using list comprehension.
21. Read a sentence from the user and convert it to a tuple of words. Pass the tuple of words
as parameter to a user-defined function that returns the tuple of words present in the odd
numbered index values.
Input: "Hello! How are you?"
Output: ("How", "you?")
1. Write the function Replicate_n_times(Lst,n) to replicate the elements of a list n times, i.e.
to replicate the elements of a list for a given number of times. Example: Lst = [1, 2, 3, 4]
Replicate_n_time(Lst,2) Lst = [1,1,2,2,3,3,4,4]
2. Explain any ten in-built methods of list with syntax and examples
3. Write a program to extract the factors of n and store it in a list.
4. Write a program to create a list of numbers between a range that are either divisible by 3
or 6
5. Write a program to delete the duplicates present in the list.
6. Write a program to print maximum and minimum in a tuple.
7. What is the difference between a list and a tuple.
8. Remove negative values from a list with the filter function
9. Filter even values out of a list with list comprehension
10. What is the difference between sort and sorted?