Page 1 :
Chapter 8: Lists, Tuples and Dictionaries, I. Fill in the blanks, 1. A set of values enclosed within [ ] is called a ___________. (list), 2. To create a list with values inputted from the keyboard, we must use the, ________________ keyword. (eval), 3. With reference to modifying values, a list is _____________ but a tuple is, _______________. (mutable , immutable), 4. The values in a tuple are enclosed within ___________.(parenthesis), 5. You can traverse a list using the ________________ loop. (for), 6. In lists, the _____________ keyword helps to add a new element at the end of the list., (append), 7. Assigning the values of a list to individual variables is called _____________ the list., (unpacking), 8. The ___________ character is used to separate the key from the value in a dictionary., (:), 9. You can form a dictionary from a separate set of keys and a set of values using the, ___________ method. (zip), 10. The key:value pairs in a dictionary have to be enclosed within _________. (quotes), II. Match the following, 1., [], a. repetition, 2., eval, b. membership operators, 3., 0, c. list, in and not, 4., d. remove item with specified value, in, 5., +, e. new item at end of list, 6., *, f. remove item at location, 7., append, g. user input, 8., insert, h. new item at specified location, starting position of values in a, 9., del, i., list, 10. Remove, j. concatenation, 1. h, 2.g , 3.i , 4.b, 5.j, 6.a, 7.e , 8.f, 9.f , 10d, III. Choose the correct answer, 1. Strings in a list should always be enclosed within ( ), i. [ ], ii. { }, iii. “ “ (correct)
Page 2 :
2. What is the number assigned to the position of the first item in a list? i. 0, (correct) ii. 1, 3. Which of the following will print a list three times?, i. print(mylist(3)) ii. print (mylist ^ 3) iii. print (mylist*3) (correct) iv. None, of the above, 4. The append keyword will add the new item:, i. at the end of the list (correct) ii. at the beginning of the list iii., at the location specified, iv. in any random location, 5. Which of the following is the correct way to unpack a list?, i. unpacklistname to var1, var2, var3… ii. listname.unpack(var1, var2, var3…) iii., var1, var2, var3 = listname (correct) iv. listname = var1, var2, var3, 6. The main difference between a list and a tuple is:, i. List can only contain numeric values whereas a tuple can contain numeric and string, values. ii. List is mutable whereas a tuple is immutable. (correct) iii. List can contain a, maximum of 256 items whereas a tuple does not have any limit., V. Record the output, 1. centuries = ["Sachin", 60, "Gooch", 44, "Hick", 40, "Kohli",39] print(centuries), ['Sachin', 60, 'Gooch', 44, 'Hick', 40,, 'Kohli', 39], 2. print (centuries[3]), 44, 3. print (centuries[1:2]), 60, 4. print (centuries[1:]), [60, 'Gooch', 44, 'Hick', 40, 'Kohli', 39], 5. print (“Hick”incenturies), True, 6. print ("hick" in centuries), False, 7. for p in centuries:, print(p), Sachin, 60
Page 4 :
dict_keys(['Name', 'Class', 'Grade', 'Eligibility']), 14. studinfo = {"Name" : "Asha", "Class" : 8, "Grade" : "A+", "Eligibility" : "Yes"}, print(studinfo.values()), dict_values(['Asha', 8, 'A+', 'Yes']), 15. wavelength = dict(zip(("Red","Blue","Green","Yellow"),(665,470,5510,600))), print(wavelength), {'Red': 665, 'Blue': 470, 'Green': 5510,, 'Yellow': 600}, 16. wavelength =dict(zip(("Red","Blue","Green","Yellow"),(665,470,550,600))), a=wavelength.pop("Red") print(a), print(wavelength), 665, {'Blue': 470, 'Green': 550, 'Yellow': 600}, VI. Debug the following, 1. flowerlist = {“rose”, “jasmine”, “lily”, “hibiscus”,”bluebell”}, flowerlist = {“rose”, “jasmine”, “lily”,, “hibiscus”,”bluebell”}, 2. marklist = eval(input(Enter five marks)), marklist = eval(input(“Enter five marks:”)), 3. print flowerlist[“3”], print(flowerlist[3]), 4. if “lily” is in flowerlist if “lily” in flowelist:, 5. del flowerlist (1), del flowerlist[1], 6. flowerlist_insert(“marigold”), flowerlist.append(“marigold”), 7. flowerlist.pop[3], flowerlist.pop(), 8. remove(flowerlist(“jasmine”), flowelist.remove(“jasmine”), 9. flowerlist.sort(ascending)