Tuples Dictionaries 1 / 50What does d.popitem() do in Python 3.7+? Removes a random item Removes the first item Removes the last inserted item Removes the item with the smallest key 2 / 50Which method returns a value for a key, and if the key is not found, inserts it with a default value? get() setdefault() update() popitem() 3 / 50What is the result of d = {1: ‘A’}; del d[1]; print(d)? {1: 'A'} {} None Error 4 / 50How do you get the number of items in a dictionary? d.size() count(d) len(d) d.length() 5 / 50Which of these can be a dictionary key? ['a', 'b'] {'a': 1} (1, 2) set([1, 2]) 6 / 50What is the output of type({})? 7 / 50What does d.update({‘c’: 3}) do? Replaces d with {'c': 3} Adds or updates 'c' in d Returns a new dictionary Error 8 / 50What is a dictionary comprehension? A way to delete dictionaries A concise way to create dictionaries A method to sort dictionaries An error handling tool 9 / 50Are dictionaries ordered in Python 3.7+? Yes No Only if sorted Only if they contain strings 10 / 50What is the output of dict([(‘a’, 1), (‘b’, 2)])? {'a': 1, 'b': 2} [('a', 1), ('b', 2)] Error {'a', 1, 'b', 2} 11 / 50How do you check if key ‘k’ exists in dictionary ‘d’? 'k' in d d.has_key('k') d.contains('k') Both A and B 12 / 50Which method returns all the values in a dictionary? values() get_values() all_values() data() 13 / 50What happens if you add a duplicate key to a dictionary? Error is raised The old value is overwritten Both values are kept The new value is ignored 14 / 50How do you remove a key ‘k’ and return its value? d.remove('k') d.pop('k') del d['k'] d.extract('k') 15 / 50Which method returns all key-value pairs as tuples? pairs() items() values() list() 16 / 50What is the result of len({‘a’: 1, ‘b’: 2})? 1 2 4 Error 17 / 50Which method removes all elements from a dictionary? delete() clear() remove_all() reset() 18 / 50How do you add a new key ‘k’ with value ‘v’ to dictionary ‘d’? d['k'] = 'v' d.add('k', 'v') d.insert('k', 'v') d.append('k', 'v') 19 / 50What does d.get(‘x’, 0) return if ‘x’ is not in d? None Error 0 False 20 / 50Which method returns all keys in a dictionary? get_keys() keys() all_keys() names() 21 / 50Dictionary keys must be ___. Mutable Immutable Strings only Integers only 22 / 50What is the output of d = {‘a’: 1}; print(d[‘a’])? 'a' 1 {'a': 1} Error 23 / 50Which brackets are used for dictionaries? () [] {} 24 / 50Dictionaries store data in ___ pairs. Index-Value Key-Value Tag-Data List-Value 25 / 50How do you create an empty dictionary? {} dict() Both A and B None of these 26 / 50What is the time complexity of accessing an element in a tuple by index? O(1) O(n) O(log n) O(n^2) 27 / 50Which function converts a list to a tuple? to_tuple() tuple() cast(tuple) list.to_tuple() 28 / 50What happens if you try T[0] = 5 on T = (1, 2)? T becomes (5, 2) Raises TypeError T becomes [5, 2] Nothing happens 29 / 50Can a tuple contain a list? Yes No Only if the list is empty Only if the tuple is nested 30 / 50What is the output of 5 in (1, 5, 10)? True False 5 Error 31 / 50Is (1, 2, 3) the same as 1, 2, 3? Yes, Python treats both as a tuple No, one is a list No, one is an error No, one is a set 32 / 50What does ‘a, b = 1, 2’ create? Two integers A tuple A list An error 33 / 50Which function returns the largest element in a tuple? largest() max() top() high() 34 / 50What is the result of tuple(‘hi’)? ('h', 'i') ('hi') ['h', 'i'] Error 35 / 50How do you delete a whole tuple ‘T’? T.delete() del T remove(T) T = None 36 / 50What is the output of a = (1, 2); b = a; print(a is b)? True False None Error 37 / 50Can you change an element inside a tuple after creation? Yes No Only using the update() method Only if it's a nested list 38 / 50What is the output of (1, 2, 3)[1:3]? (1, 2) (2, 3) (1, 3) (2,) 39 / 50Which method finds the first index of a value in a tuple? index() find() search() locate() 40 / 50What is the result of (1, 2) * 2? (2, 4) (1, 2, 1, 2) Error (1, 2, 2) 41 / 50What is tuple unpacking? Deleting a tuple Assigning tuple elements to multiple variables Converting a tuple to a list Joining two tuples 42 / 50Can a tuple be used as a dictionary key? Yes, always No, never Only if it contains immutable elements Only if it is empty 43 / 50What is the output of len((10, 20, 30))? 2 3 30 Error 44 / 50Which method returns the number of times a value appears in a tuple? find() count() index() search() 45 / 50What is the result of (1, 2) + (3, 4)? (4, 6) (1, 2, 3, 4) [1, 2, 3, 4] Error 46 / 50How do you access the first element of tuple T? T[0] T(0) T.first() T{0} 47 / 50What is the output of print(type((1, 2)))? 48 / 50Which brackets are used to define a tuple? [] {} () 49 / 50Tuples are mutable. True False Only if they contain lists Depends on the Python version 50 / 50How do you create a tuple with one element? (1) (1,) [1] {1} Your score isThe average score is 8%