NEW
Font size
WorksheetsLECTURE 03 Quizs (20.11.2025)
Total questions: 20
Worksheet time: 10mins
Which method would you use to remove a specific item from a Python set if you are not sure the item exists?
remove()
discard()
pop()
delete()
What will be printed by the following code? (Try it in a Python interpreter!) ```python data = [10, 20, 10, 30, 20] print(list(set(data))) ```
[10, 20, 10, 30, 20]
[10, 20, 30]
[30, 10, 20] (order may vary)
[20, 30, 10, 10, 20]
You are designing a program that must store a collection of items where order does not matter and duplicates must be removed automatically. Which Python data type should you choose and why?
List, because it is ordered and allows duplicates
Tuple, because it is immutable
Set, because it is unordered and stores only unique elements
Dictionary, because it stores key-value pairs
True or False: A Python list is an ordered collection of items that can be changed after creation.
True
False
You need to measure the execution time of a function in Python as accurately as possible. Which approach should you use and why?
Use time.time() because it is simple
Use time.clock() because it is deprecated
Use time.perf_counter() because it provides the highest available resolution timer
Use datetime.now() because it returns the current date and time
True or False: Tuples are generally preferred over lists when the data must remain unchanged.
True
False
Which method removes all items from a Python set?
clear()
remove()
discard()
pop()
True or False: Python sets automatically remove duplicate elements.
True
False
Why are sets more efficient than lists for checking if an item exists?
Sets are ordered
Sets use hashing for fast lookups
Sets store data in arrays
Sets are immutable
Which Python data type is best for removing duplicates from a sequence?
List
Dictionary
Set
Tuple
Write a Python function that takes a list with duplicate values and returns a new list with only unique values. Which of the following implementations is correct? (Test it in a Python interpreter!)
```python def unique(data): return list(set(data)) ```
```python def unique(data): return data ```
```python def unique(data): return set(list(data)) ```
```python def unique(data): return data.sort() ```
A Python module is:
A folder containing multiple files
A single Python file (.py)
A built-in function
A compiled program
True or False: Sets in Python are ordered collections.
True
False
Which method would you use to add an item to a Python list?
add()
append()
insert()
update()
Which function is recommended for measuring the execution time of a Python process?
time.time()
time.clock()
time.perf_counter()
datetime.now()
Given the function: ```python def get_unique_elements(data): unique_list = list(set(data)) print(unique_list) ``` What is the main advantage of using `set(data)` in this function?
It sorts the data
It removes duplicate elements efficiently
It makes the list immutable
It reverses the list
What is the result of running the following code? ```python print(set([1, 2, 2, 3])) ```
{1, 2, 2, 3}
[1, 2, 3]
{1, 2, 3}
(1, 2, 3)
If you want to ensure that a collection of items cannot be changed, which Python data type should you use?
List
Set
Tuple
Dictionary
Which of the following best describes the difference between a Python module and a package?
A module is a folder, a package is a file
A module is a single file, a package is a folder containing modules
Both are the same
A package is a function, a module is a class
True or False: Tuples in Python are mutable.
True
False
