37 solutions available
Question 1Assertion (A): List in Python is a collection of values of any type.Reasoning (R): In lists, you can change the elements of a list in...
Question 3Which of the following statements is correct about list?List can contain values of mixed data types.List can contain duplicate values.A...
Question 8The sequential accessing of each of the elements in a list is called:List IndexingList TraversalList SlicingList Accessing
Question 2What are the similarities between strings and lists?
Question 4Define the following functions:(a) len()(b) append()(c) extend()(d) pop()(e) remove()(f) del(g) sort()(h) sorted()(i) copy()(j) count()(k)...
Question 5What is the difference between insert() and append() methods of a list?
Question 6Suppose L = [10, ["few", "facts", "fun"], 3, 'Good']Consider the above list and answer the following:(a) L[3:](b) L[::2](c) L[1:2](d) L[1]...
Question 7Find the output of the following:L1=[1, 2, 3] L2=[4, 5, 6] print(L1+list ("45") ) print(L1.pop()) L1.remove (2) print(L1) L1.extend (L2)...
Question 8(b)What will be the output of the following statement?list1 = [12, 32, 65, 26, 80, 10] sorted(list1) print(list1)
Question 8(c)What will be the output of the following statement?list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list1[::-2] list1[:3] + list1[3:]
Question 8(d)What will be the output of the following statement?list1 = [1, 2, 3, 4, 5] list1[len(list1)-1]
Question 9What will be the output of the following code segment?myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for i in range(0, len(myList)): if i % 2...
Question 10(a)What will be the output of the following code segment?myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] del myList[3:] print(myList)
Question 10(b)What will be the output of the following code segment?myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] del myList[:5] print(myList)
Question 10(c)What will be the output of the following code segment?myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] del myList[::2] print(myList)
Question 11Write the output of the following Python program code:Str2 = list("Cam@123*") for i in range(len(Str2)-1): if i==5: Str2[i] =...
Question 12Differentiate between append() and extend() methods of list.
Question 13Write a program to read a list of n integers (positive as well as negative). Create two new lists, one having all positive numbers and the...
Question 14Write a program to find the largest and the second largest elements in a given list of elements.Solutionnums = eval(input("Enter the list:...
Question 15Write a program to read a list of n integers and find their median.Note: The median value of a list of values is the middle one when they...
Question 16What is the basic principle of sorting in insertion sort?
Question 17Which sorting is more efficient—bubble sort or insertion sort? Give reason.
Question 18Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements...
Question 19Write a program to create a list of elements. Input an element from the user that has to be inserted in the list. Also, input the position...
Question 20Write a program to read elements of a list and do the following:(a) The program should ask for the position of the element to be deleted...
Question 21WAP that takes an array S as an argument and add all the odd values and display the sum.SolutionS = eval(input("Enter the array: ")) total...
Question 22Write a program to calculate mean of a given list of numbers.Solutionnumbers = eval(input("Enter a list: ")) if len(numbers) == 0:...
Question 23WAP in Python to delete all duplicate elements in a list.For example,If list is: [5, 2, 4, -5, 12, 2, 7, 4]After deleting duplicate...
Question 24Write a program to calculate the minimum elements of a given list of numbers.Solutionl = eval(input("Enter a list: ")) m = min(l)...
Question 25Write a code to calculate and display total marks and percentage of a student from the given list storing marks of a...
Question 26WAP to multiply an element by 2 if it is odd index for a given list containing both numbers and strings.Solutionmixed = eval(input("Enter...
Question 27WAP to count the frequency of an element in a given list.Solutionmy_list = eval(input("Enter the list: ")) c = int(input("Enter the...
Question 28WAP to shift elements of a list so that first element moves to the second index and second index moves to the third index, etc., and last...
Question 29An array Num contains the following elements:3, 25, 13, 6, 35, 8, 14, 45Write a function to swap the content with next value divisible by...
Question 30The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list:stRecord =...
Question 31What will be the status of the following list after fourth pass of insertion sort and fourth pass of bubble sort used for arranging...
Question 32Write the steps to arrange the following elements using insertion sort:12, 5, 14, 8, 3, 54, 25, 10, 27, 30