67% found this document useful (3 votes)
6K views8 pages

Preeti Arora List Questions

Preeti Arora Class XIth List Questions

Uploaded by

Ghanshyam Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
67% found this document useful (3 votes)
6K views8 pages

Preeti Arora List Questions

Preeti Arora Class XIth List Questions

Uploaded by

Ghanshyam Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
ANSWERS TO FILL IN THE BLANKS 1. sequence 2. homogeneous 3. integer 4. square brackets 5. mutable 6. removel) 7. Sorting 8. pop()/del() 9. append() 10. comparison SOLVED QUESTIONS 1. What is a list? "ANS. Alist is a mutable sequence of values which can he of any type and they are indexed by an integer. 2. What are the differences between lists and strings? ‘Ans. The differences between lists and strings are: (a) Strings cannot be changed, but lists are mutable, they can be changed. (b) Usts use square brackets unlike strings which are enclosed in quotes, (c) Strings store single type of elements but list can store elements of different types, 3. What is the difference between extend() and append()? Ans. The append() method adds a single item to the existing lst. It doesn’t return a new list, rather it modifies the original lst. The extend) adds al the items of alist at the end of another list 4, What is the difference between pop() and remove()? Ans. pop) function removes the element from the specified index, and also return the element which was removed. no index value is provided in pop), then last element is deleted. Function remove() is used when we know the element to be deleted but not the index of the element, 5. Following are the statements for creating lists, Find the errors in the statements and rewrite the same after correcting them. {a) L= 1,6,a,8 (b) 12=(10) (c) Li={(0,1,2,3] ['my", "book" }] (2) L1=(10,1,2,3}, (4,5, 61) (e) Li=f'at, "b!, 0 (1,2,3,A}) (f) L1=[Aman, Lakshay, Aushim, Nishant] Ans, (a) L1= (1,6; 'a',8) (b) L2=(10) (c) L1=( (0,1, 2,3], ['my", "book" }} (@) L1=((0,1,2,31, (4,5, 61] (e) Li=[tat, tt, tot, (1.2/3, 'A'T] {f) Li=(‘Aman', "Lakshay', 'Aushim', 'Nishant'} 6. Suppose L=["abc", (6,7,8], 3, 'mouse'] Consider the above list and answer the following: (a) £13:] (b) LE:22] (o) L222) (@) 11) Ans. (a) b(3:] {e) L222) ((6, 7, 8)] (@ 20) 7 (2) Delete a given element from the list. (c) Delete the 3° element from the list (e) Add an element in the beginning of the ls. Ans. (a) remove() {d) append() 8. Write the output of the following: {a) stri="book' print (List (str1)) (b) LH12, 4y Sy 6 2, 3, 4, Ay TDs count = L.count (4) print (count) (o) b= (20, 45, 2, 20, 30, 40) L.sort () print (L) L.reverse() print (L) (2) Lettpty wt, "rt, L.renove("r") print (L) print (L.pop()) del L(2] print (L) © (e) L1=[10,20, 30, 40) L1.clear () print(bl) ‘Ans. (a) ["b', tot, to", TR" () 3 (0) (2, 10, 20, 30, 40, 45] (45, 40, 30, 20, 10, 2) (d) (tpt, twhy tat, tty a Cpt, a) 0 9, Write the output of the following: — L1=(500, 600] 12=[35, 45] Li.append (700) Ll extend (12) Li. insert (25,2) print (L1) print (L1+L2) print(b1) print (L1.index(35)) print (L2*2) ‘Ans. (500, 600, 700, 35, 45, 2) [500, 600, 700, 35, 45, 2, 35, 45] [500, 600, 700, 35, 45, 2] 3 (35, 45, 35, 45] | (o) (4) (fl (b) (e) 7. Write the most appropriate list method to perform the following tasks Get the position of an item in ‘Add single elemé ‘Add elements in the list at the en index) insert() the list. rent at the end of the list. 1d of a list. {c) pop/dell) (A) extend() [BS 10. Write the output of the following: L=() for i in range (6,10): L-append (i) for i in range(10,4,-2): Ll -append (i) for i in range (1en(L1)) L2. append (L(i]+L1 (41) 12. append (len (L) ~Len(L1)) print (12) Ans. (16, 15, 14, 1) 11, Write the output of the following: (a) L=(1,2,3,4,5,6,7,8, 9,10] S=( i for i in L if i82==0) print(s) (b) A= (1,23, 4] B=[value*3 for value in Al print (B) Ans. (a) (2,4, 68/10] (b) 13,6,9,12) 12. Write the output of the following Python program code: STRI= List ("SNo4") for i in range(Len(STR1)) if iss3 xeint (i) xtex-3 STR [i]=x elif (STRI(i).islower()): STRI (i) = STR1{4] -upper() else: STR [1] =STRI [i] *2 print (STRI) Ans. ('SS', 3, '0", 4") 13, Write the output of the following Python program code: Le "neat" xen Lis) count=1 for i in Li if iin ['a','e',"it,'0', 'u']: XeXHi .swapcase () else: if (count #2) !=0) : (+str ( (Len (L{:count})}) count=count +1 print (X) Ans. 1EAt re 14. WAP to accept integer array and search a particular value in the array. itexists, then the function should display “exists”, otherwise should display “Does not exist” Ans. L~ (10,20, 3,100, 65,87, 2] Neint (input ("Enter the nu er to be searched:")) for 4 in range (len (ty): Af type (Li}) and Ufi loot: print ("Exists at position: ", i) break else: print ("Does not exist") Output: >>>Enter the number to be searched :75 Does not exist >>Enter the number to be searched :100 Exists at position :4 1S. WAP that takes a list ‘Las an argument, adds 5 in all the odd values and 10 in all the even values of the list L. Also display the list. Ans. L= (10,20, 3,100, 65,87, 2) for i in range(len(t)) : Af type (L[i})==int: LE LLL] 82= LUAl=LUil +10 else: LUD*LUi}+5 print (L) Output: [20, 30, 8, 110, 70, 92, 12) 16. WAP to display unique and duplicate items of a given list. Ans. L1=[2,7,1,4,9,5,1,4,3] L2=1) L3=[] for i in Li: if i not in 12: L2.append(i) els L3.append (i) print(L2) print (L3) Output: (2, 7, 1, 4, 9, Sy 3) a 1, 41 17, WAP to exchange first half elements of Ist with second half elements of list assuming list is having even number of elements, Ans. L=(10, 20, 30,40, 50, 60, 70) xmint (Len (L)/2) for 4 in range (x) : LS), Lixtd) ob (xt), L(4) “ print (L) Output: [40, 50, 60, 10, 20, 30, 70) sarees uns ure 18. WAP to enter a string and count number of words in the given string Suppose string is: Jam fine Output should be Number of words =3 Ans. str1=input ("Enter a sentence Lestrl.split() count=0 for i in range (len (L)) count+=1 Print (‘Number of words=", count) Output: Enter a sentence: I am fine Number of words =3 19. WAP to display frequencies of all the elements of a list Ans. L=(3,21, 5,6, 3,8, 21,6] if i not in 12 count (i) append (x) 12. append (i) print ("Element', '\t\t', 'Frequency') for i in range(len(L1)): print (L2(i],"\t\e\e", LI) Output: Element Frequency 3 2 a 2 5 1 6 2 1 20. WAP to display square of an element if it isan integer and change the case if element is a string. List is received as argument which contains both numbers and strings. Ans, L=(10, "FUN", 40, "FEW", 50, "FULL"] for i in range (len(L)): if type (b(i]) LUi}= bli) #2 elif type (L[i]==str) : L[i] = (L[4]) -swapcase () print (L) Output: [100, "fun", 1600, ‘few’, 2500, *full") 21. WAP in Python, where list Lis p [°RINKU", "AUSHIM", "VUAYA": ‘Ans. L= ("RINKU", "AUSHIM" count =0 for i in: assed as an argument. Display those strings which are string with "AKHTA\ 7 /VIOAYA", "AKHTAR", "LEENA", “TARUN" 4410] in (raat): count+=1 print (ip Print ("Appearing™, count, "times") Output: AUSHIM “AKHTAR AMAR Appearing 3 times 22. WAP to find and display the sum of all the values which are ending with 3 from alist ist ‘U's received 9s argument and displays the sum. Ensure that function is able to handle various situations, viz. list containing numbers and strings. eg. list is: [33,13,92,99, Output will be 49 Ans. L=(33, 13, 92,99, 3,12] sum=0 x=len(L) for i in range(0,x): if type(Llil) if L[i}$10==3: sum ##L [i] : print (sum) 12) at: 23. A list Num contains the following elements: 3,21, 5,6, 14,8, 14,3 WAP to swap the content with next value divisible by 7 so that the resultant array will look like: 3,5, 21, 6,8, 14,3, 14 Ans. num=(3, 21, 5, 6, 14, 8, 14, 3) =1en (num) iso while ich: if num[i]$7==0: ‘, num{i}, num(i+l]= num{itl], num{i) isit2 PT TEE EEE EEE LER Eee Eeeeeeee SUC La ed else: init print (num) Output: : (3, 5, 21, 6, 8, 14, 3, 14] 24. WAP to shift the negative numbers to left and the positive numbers to right so that the resultant list will look like. Original list [-12, 11, -13,-5, 6,~7, 5, -3,-6] Output should be [11, 6, 5, -6,-3, -7, -5, -13, -12] LOLs aie ie ee et all al ll cl alti Ans. 1=[-12, 11, -13, -5, 6, -7, 5, - n=len (1) print (Original List:",1) for i in range(n-1) for j in range (n-i-1) : if 13] <0: UG AGL GHG) print ("After shifting list is:",1) Output: Original list: [-12, 11, -13, -5, 6-7, After shifting list is: (1i, 6, 5, ~6, ~ -13, -12) UNSOLVED QUESTIONS === 1, What are the various ways to create a list? 2, What are the similarities between strings and lists? 3. Why are lists called mutable data type? 4, What is the difference between insert() and append{) methods of a list? 5. Suppose L=(10, ("fen", "facts", "fun"], 3, 'Good") Consider the above list and answer the following: L131 (i) LEe22] (ii) Lez (w) Ba) 6, Find the output of the following L1=(1, 2, 3] 12=[4,5,6] print(Ll¢ List ("45")) print(L1.pop()) Li. remove (2) print (Ll) Ll.extend(L2) print (L2) 7. Write the output of the following: import statistics 20, 40, 50, 60, 20, 30, 40, 70) count = L.count (40) print (count) tatistics.mean(L) print (x) ? L.sort () print (L) L. reverse () print (L) 7 8 Write the output of the following Python program code: str2= list ("Cam@123*") for 1 in range (len (Str2)-1) : if lens: Str2[ij= str2(i]*2 elif (Str2 [i] -isupper ()): str2 [i] = Str2 [i]*2 elif (Str2 [i] isdigit ()): str2 [i] = print (Str2) 8 g 2 3 Fy = 8 3 E oS r 5, Write 2 program that takes an array Sas an argument and add all the odd values and splay the sum. 20. Write a program to calculate mean of a given list of numbers. 41, Write a program to calculate the minimum element of a given lst of numbers. 12 Write a code to caleulate and dsplay total marks and percentage ofa student from the given list storing marks of a student. 15, Wilte a program to multiply an element by 2 fits odd index fora glven list containing both numbers and strings. 14. Write a program to count the frequency of an element in a glven lis. 45. Write a program to shif: elements of alist so that the frst element moves to the secund Index and the Second index moves to the third index, etc,, and the last element shifts to the first position. Suppose list is [10,20,30,40] After shifting it should look lke: [20,30,40,10] 16. An array Num contains the following elements: 3, 25, 13, 6, 35, 8, 14, 45 Write a function to swap the content with next value divisible by 5 so that the resultant array will look like: 25, 3, 13, 35, 6, 8, 45, 14

You might also like