104 solutions available
Question 1Lists are mutable data types and thus their values can be changed.
Question 2To create an empty list, function list() can used.
Question 3The + operator adds one list to the end another list.
Question 4The * operator replicates a list.
Question 5To check if an element is in list, in operator is used.
Question 6To delete a list slice from a list, del statement is used
Question 7A nested list contains another list as its member.
Question 8The insert() function is used to insert element at a designated position in a list.
Question 9The pop() function is used to delete element to remove an element from designated index in a list.
Question 10The extend() function can append a list elements to a list.
Question 11The sort() function sorts a list and makes changes in the list.
Question 12The sorted() function sorts a list and returns another list.
Question 1List can contain values of these types:integersfloatsliststuplesall of these ✓
Question 2Which of the following will create an empty list?L = [ ] ✓L = list(0)L = list( ) ✓L = List(empty)
Question 3Which of the following will return the last element of a list L with 5 elements?L[5]L[4] ✓L[-1] ✓L[6]
Question 4If L = [1, 2] then L * 2 will yield[1, 2] * 2[1, 2, 2][1, 1, 2, 2][1, 2, 1, 2] ✓
Question 5If L1 = [1, 3, 5] and L2 = [2, 4, 6] then L1 + L2 will yield[1, 2, 3, 4, 5, 6][1, 3, 5, 2, 4, 6] ✓[3, 7, 11][1, 3, 5, [2, 4, 6]]
Question 6Given a list L= [10, 20, 30, 40, 50, 60, 70], what would L[1 : 4] return?[10, 20, 30, 40][20, 30, 40, 50][20, 30, 40] ✓[30, 40, 50]
Question 7Given a list L= [10, 20, 30, 40, 50, 60, 70], what would L[2 : -2] return?[10, 20, 30, 40][20, 30, 40, 50][20, 30, 40][30, 40, 50] ✓
Question 8Given a list L= [10, 20, 30, 40, 50, 60, 70], what would L[-4 : -1] return?[20, 30, 40][30, 40, 50][40, 50, 60] ✓[50, 60, 70]
Question 9Given a list L= [10, 20, 30, 40, 50, 60, 70], what would L[-3 : 99] return?[20, 30, 40][30, 40, 50][40, 50, 60][50, 60, 70] ✓
Question 10To find the last element of list namely 'smiles' in Python, .......... will be used.smiles[0]smiles[-1] ✓smiles[lpos]smiles[:-1]
Question 11Out of the following, what is correct syntax to copy one list into another?listA = listB[ ]listA = listB[:] ✓listA = listB[ ]( )listA =...
Question 12What is printed by the Python code? print(list(range(3)))[0, 1, 2, 3][1, 2, 3][0, 1, 2] ✓0, 1, 2
Question 13Which of the following commands will create a list?listl = list( )listl = [ ]listl = list([1, 2, 3])all of these ✓
Question 14What is the output when we execute list("hello")?['h', 'e', 'l', 'l', 'o'] ✓['hello']['llo']['olleh']
Question 15What gets printed?names = ['Hasan', 'Balwant', 'Sean', 'Dia'] print(names[-1][-1])HnHasanDiaa ✓
Question 16What is the output of the followingl = [None] * 10 print(len(l))10 ✓0Syntax ErrorNone
Question 17Consider the list aList - ["SIPO", [1, 3, 5, 7] ]. What would the following code print?print(aList[0][1], aList[1][1])S, 3S, 1I, 3 ✓I, 1
Question 18Which of the following is a standard Python library function and not an exclusively list function?append( )remove( )pop( )len( ) ✓
Question 19Which of the following can add only one value to a list?add( )append( ) ✓extend( )none of these
Question 20Which of the following can add a list of elements to a list?add( )append( )extend( ) ✓none of these
Question 21Which of the following will always return a list?max( )min( )sort( )sorted( ) ✓
Question 22Which of the following can delete an element from a list if the index of the element is given?pop( )remove( )del ✓all of these
Question 23Which of the following can delete an element from a list, if its value is given?pop( )remove( ) ✓delall of these
Question 24Which of the following searches for an element in a list and returns its index?search( )find( )index( ) ✓lsearch( )
Question 25Which of the following can copy a list to another list?list( ) ✓new( )copy( ) ✓= operator
Question 1The list( ) and copy( ) are the similar functions.False
Question 2The pop( ) and remove( ) are similar functions.False
Question 3A = [ ] and A = list( ) will produce the same result.True
Question 4Lists once created cannot be changed.False
Question 5To sort a list, sort( ) and sorted( ), both can be used.True
Question 6The extend( ) adds a single element to a list.False
Question 7The append( ) can add an element in the middle of a list.False
Question 8The insert( ) can add an element in the middle of a list.True
Question 9The del statement can only delete list slices and not single elements from a list.False
Question 10The del statement can work similar to the pop( ) function.True
Question 1Discuss the utility and significance of Lists in Python, briefly.AnswerPython lists are containers that can store an ordered list of values...
Question 2What do you understand by mutability? What does "in place" memory updation mean?AnswerMutability means that the value of an object can be...
Question 3Start with the list [8, 9, 10]. Do the following using list functions:Set the second entry (index 1) to 17Add 4, 5 and 6 to the end of the...
Question 4If a is [1, 2, 3]what is the difference (if any) between a * 3 and [a, a, a]?is a * 3 equivalent to a + a + a?what is the meaning of a[1:1]...
Question 5What's a[1 : 1] if a is a list of at least two elements? And what if the list is shorter?Answera[x:y] returns a slice of the sequence from...
Question 6How are the statements lst = lst + 3 and lst += [3] different, where lst is a list? Explain.AnswerThe statement lst = lst + 3 will give...
Question 7How are the statements lst += "xy" and lst = lst + "xy" different, where lst is a list? Explain.AnswerThe statement lst = lst + "xy" will...
Question 8What's the purpose of the del operator and pop method? Try deleting a slice.AnswerThe del statement is used to remove an individual element...
Question 9What does each of the following expressions evaluate to? Suppose that L is the list["These", ["are", "a", "few", "words"], "that", "we",...
Question 10What are list slices? What for can you use them?AnswerList slice is an extracted part of the list containing the requested elements. The...
Question 11Does the slice operator always produce a new list?AnswerSlice operator copies only the requested elements of the original list into a new...
Question 12Compare lists with strings. How are they similar and how are they different?AnswerThe similarity between Lists and Strings in Python is...
Question 13What do you understand by true copy of a list? How is it different from shallow copy?AnswerTrue copy of a list means that the elements of...
Question 14An index out of bounds given with a list name causes error, but not with list slices. Why?AnswerWhen we use an index, we are accessing a...
Question 15What is the difference between appending a list and extending a list?AnswerAppending a listExtending a listFor appending to a list,...
Question 16Do functions max( ), min( ), sum( ) work with all types of lists.AnswerNo, for max() and min() to work on a list, the list must contain...
Question 17What is the difference between sort( ) and sorted( )?Answersort( )sorted( )It modifies the list it is called on. That is, the sorted list...
Question 1What is the difference between following two expressions, if lst is given as [1, 3, 5](i) lst * 3 and lst *= 3(ii) lst + 3 and lst +=...
Question 2Given two lists:L1 = ["this", 'is', 'a', 'List'], L2 = ["this", ["is", "another"], "List"]Which of the following expressions will cause an...
Question 3From the previous question, give output of expressions that do not result in error.AnswerL1 == L2 gives output as false because L1 is not...
Question 4Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88]Which list slice will return [12, 25.7, [2, 1, 0, 5]]?Which expression will return...
Question 5Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:[3, 4.5, 12, 25.7, 88][3, 4.5, 12, 25.7][ [2,...
Question 6What will the following code result in?L1 = [1, 3, 5, 7, 9] print (L1 == L1.reverse( ) ) print (L1)AnswerOutputFalse [9, 7, 5, 3, 1]...
Question 7Predict the output:my_list= [ 'p', 'r', 'o', 'b', 'l' , 'e', 'm'] my_list[2:3] = [] print(my_list) my_list[2:5] = []...
Question 8Predict the output:List1 = [13, 18, 11, 16, 13, 18, 13] print(List1.index(18)) print(List1.count(18)) List1.append(List1.count(13))...
Question 9Predict the output:Odd = [1,3,5] print( (Odd +[2, 4, 6])[4] ) print( (Odd +[12, 14, 16])[4] - (Odd +[2, 4, 6])[4] )AnswerOutput4 10...
Question 10Predict the output:a, b, c = [1,2], [1, 2], [1, 2] print(a == b) print (a is b)AnswerOutputTrue False ExplanationAs corresponding elements...
Question 11Predict the output of following two parts. Are the outputs same? Are the outputs different? Why?(a)L1, L2 = [2, 4] , [2, 4] L3 = L2...
Question 12Find the errors:L1 = [1, 11, 21, 31]L2 = L1 + 2L3 = L1 * 2Idx = L1.index(45)AnswerLine 2 — L2 = L1 + 2 will result in error as one element...
Question 13aFind the errors:L1 = [1, 11, 21, 31] An = L1.remove(41)AnswerL1.remove(41) will cause an error as 41 is not present in L1.
Question 13bFind the errors:L1 = [1, 11, 21, 31] An = L1.remove(31) print(An + 2)AnswerAn + 2 will cause an error because remove() function does not...
Question 14aFind the errors:L1 = [3, 4, 5] L2 = L1 * 3 print(L1 * 3.0) print(L2)AnswerThe line print(L1 * 3.0) causes an error as Python does not...
Question 14bFind the errors:L1 = [3, 3, 8, 1, 3, 0, '1', '0', '2', 'e', 'w', 'e', 'r'] print(L1[: :-1]) print(L1[-1:-2:-3])...
Question 15What will be the output of following code?x = ['3', '2', '5'] y = '' while x: y = y + x[-1] x = x[:len(x) - 1] print(y) print(x)...
Question 16Complete the code to create a list of every integer between 0 and 100, inclusive, named nums1 using Python, sorted in increasing...
Question 17Let nums2 and nums3 be two non-empty lists. Write a Python command that will append the last element of nums3 to the end of...
Question 18Consider the following code and predict the result of the following statements.bieber = ['om', 'nom', 'nom'] counts = [1, 2, 3] nums =...
Question 19What is the output of the following code?numbers = list(range(0, 51, 4)) results = [] for number in numbers: if not number % 3:...
Question 20Following code prints the given list in ascending order. Modify the code so that the elements are printed in the reverse order of the...
Question 1Write a program to increment the elements of a list with a number.Solutionlst = eval(input("Enter a list: ")) print("Existing list is:",...
Question 2Write a program that reverses a list of integers (in place).Solutionl = eval(input("Enter a list: ")) print("Original list:", l)...
Question 3Write a program that inputs two lists and creates a third, that contains all elements of the first followed by all elements of the...
Question 4Ask the user to enter a list containing numbers between 1 and 12. Then replace all of the entries in the list that are greater than 10 with...
Question 5Ask the user to enter a list of strings. Create a new list that consists of those strings with their first characters removed.Solutionl1 =...
Question 6Write a program to check if a number is present in the list or not. If the number is present, print the position of the number. Print an...
Question 7aCreate the following lists using a for loop:A list consisting of the integers 0 through 49.Solutionl = [] for i in range(50):...
Question 7bCreate the following lists using a for loop:A list containing the squares of the integers 1 through 50.Solutionl = [] for i in range(1,...
Question 7cCreate the following lists using a for loop:The list ['a','bb','ccc','dddd', . . . ] that ends with 26 copies of the letter z.Solutionl =...
Question 8Write a program that takes any two lists L and M of the same size and adds their elements together to form a new list N whose elements are...
Question 9Write a program rotates the elements of a list so that the element at the first index moves to the second index, the element in the second...
Question 10Write a program that reads the n to display nth term of Fibonacci series.The Fibonacci sequence works as follows:element 0 has the value...
Question 11aWrite programs as per following specifications:'''Print the length of the longeststring in the list of strings str_list.Precondition :...
Question 11bWrite programs as per following specifications:'''L is a list of numbers. Print a new list where each element is the corresponding...
Question 12Write a program to read two lists num and denum which contain the numerators and denominators of same fractions at the respective indexes....
Question 13Write a program to display the maximum and minimum values from the specified range of indexes of list.Solutionl = eval(input("Enter the...
Question 14Write a program to move all duplicate values in a list to the end of the list.Solutionl = eval(input("Enter the list: ")) dedup = [] dup =...
Question 15Write a program to compare two equal sized lists and print the first index where they differ.Solutionprint("Enter two equal sized lists")...