Data Structures & Operations

Python Coding Quiz - Data Structures & Operations

Python Coding Quiz - Data Structures & Operations

Answer the coding questions below by selecting all applicable options:

Time Remaining: 05:00

1. Which code snippets correctly create a list with elements 1, 2, and 3? (Select all that apply)

A) my_list = [1, 2, 3] B) my_list = list(1, 2, 3) C) my_list = [1, 2, 3,] D) my_list = {1, 2, 3}

2. Which code snippets correctly create a dictionary with keys 'a' and 'b'? (Select all that apply)

A) my_dict = {'a': 1, 'b': 2} B) my_dict = dict(a=1, b=2) C) my_dict = {'a', 1, 'b', 2} D) my_dict = dict([('a', 1), ('b', 2)])

3. Which code snippets correctly access the last element of a list my_list? (Select all that apply)

A) my_list[-1] B) my_list[len(my_list)] C) my_list[len(my_list) - 1] D) my_list.last()

4. Which of the following correctly removes an item from a set my_set? (Select all that apply)

A) my_set.remove(2) B) my_set.delete(2) C) my_set.pop(2) D) my_set.discard(2)

5. Which code snippets remove duplicates from a list my_list? (Select all that apply)

A) my_list = list(set(my_list)) B) my_list.remove_duplicates() C) my_list = [*set(my_list)] D) my_list.unique()

6. Which methods add elements to a dictionary my_dict? (Select all that apply)

A) my_dict['key'] = 'value' B) my_dict.update({'key': 'value'}) C) my_dict.add('key', 'value') D) my_dict.append('key', 'value')

7. Which code snippets correctly check if a dictionary my_dict contains the key 'a'? (Select all that apply)

A) 'a' in my_dict B) my_dict.has_key('a') C) my_dict.contains('a') D) my_dict.keys().contains('a')

8. Which code snippets correctly convert a list my_list to a set? (Select all that apply)

A) my_set = set(my_list) B) my_set = {my_list} C) my_set = my_list.set() D) my_set = {*my_list}

9. Which methods retrieve the values from a dictionary my_dict? (Select all that apply)

A) my_dict.values() B) list(my_dict.values()) C) my_dict.get_values() D) my_dict["values"]

10. Which of the following correctly checks if 5 is in the list my_list? (Select all that apply)

A) if 5 in my_list: B) if my_list.contains(5): C) if 5 in my_list[]: D) if 5 in list(my_list):