33 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 8Assertion (A): List is mutable data type.Reasoning (R): In-place change is not possible in list elements.Both A and R are true and R is the...
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 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 insert() 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 16Write 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 17Write 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 18Write 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 19Write a program that accepts elements of a list S and adds all the odd values and displays the sum.SolutionS = eval(input("Enter list: "))...
Question 20Write a program to calculate mean of a given list of numbers.Solutionnumbers = eval(input("Enter a list: ")) if len(numbers) == 0:...
Question 21WAP 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 22Write a program to calculate the minimum elements of a given list of numbers.Solutionl = eval(input("Enter a list: ")) m = min(l)...
Question 23Write a code to calculate and display total marks and percentage of a student from the given list storing marks of a...
Question 24WAP 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 25WAP to count the frequency of an element in a given list.Solutionmy_list = eval(input("Enter the list: ")) c = int(input("Enter the...
Question 26WAP 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 27An 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 28The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list:studRecord =...