Tutorial-3
Tutorial-3
DAI-101
Q3 What is the purpose of using lambda functions with map() and filter() functions in Python?
(a) To apply the lambda function to all elements of an iterable
(b) To remove all elements from an iterable
(c) To sort the elements of an iterable
(d) To create a new iterable with selected elements
Q6 Consider the following list as an input: numbers = [1, 2, 3] Which of the following would produce the result: [2]. Select
all that apply:
(a) list(filter(lambda x: (x + 1) * 3 / 3 % 3 == 0, numbers))
(b) list(filter(lambda x: x > 1, numbers))
(c) list(filter(lambda x: 2, numbers))
(d) list(filter(lambda x: x % 2 == 0, numbers))
(a) 5
(b) 6
(c) Error
(d) 5.0
Q10 Which of the following string methods returns a new string with the first character of each word capitalized?
(a) capitalize()
(b) title()
(c) upper()
(d) swapcase()
Q.16 What built-in Python data type is best suited for implementing a queue?
(a) dictionary
(b) set
(c) List
(d) None. You can only build a queue from scratch
Q17. Which of the following is true about Python's sorted() function compared to the .sort() method of lists?
(a) sorted() modifies the original list, while .sort() returns a new list
(b) sorted() returns a new list, while .sort() modifies the original list
c) Both sorted() and .sort() modify the original list
d) Both sorted() and .sort() return a new list
Q24. In Python, when using sets, you use...........to calculate the intersection between two sets
and ..................to calculate the union.
(a) Intersect ; union
(b) | ; &
(c) & ; |
(d) && ; ||
Q32. How would you access and store all the keys in this dictionary at once?
fruit_info = {'fruit': 'apple', 'count': 4, 'price': 90}
(a) my_keys = fruit_info.to_keys()
(b) my_keys = fruit_info.all_keys()
(c) my_keys = fruit_info.keys
(d) my_keys = fruit_info.keys()
Q33. What is the proper way to write a list comprehension that represents all the keys in this dictionary?
fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}
(a) fruit_names = [x in fruits.keys() for x]
(b) fruit_names = for x in fruits.keys() *
(c) fruit_names = [x for x in fruits.keys()]
(d) fruit_names = x for x in fruits.keys()
Q34. Suppose d = {“peter”:40, “michel”:45}, to delete the entry for “peter” what commands can we use?
a) d.delete("peter":40)
b) d.pop("peter")
c) del d["peter"]
d) del d("peter":40)
a) inside function g
inside function f
b) inside function f
inside function g
c) Recursion Error
inside function g
d) inside function f
inside function g
Q39. Which of the following are the characteristics of the Set (MSQ)
a) Unordered
b) Itself Mutable
c) No Duplicates
d) Can't contain mutable data types
e) Can Contain mutable data types
Q40. Which of the following are the characteristics of the Dict. (MSQ)
a) Mutable
b) keys can't be duplicated
c) keys can't be mutable items
d) Keys can be mutable
e) Maintained Order