0% found this document useful (0 votes)
6 views4 pages

Python Data Structures Test Worksheet

The document is a Python Data Structures Test Worksheet consisting of various sections that cover advanced operations on lists, tuples, dictionaries, and sets. Each section contains specific tasks that require the implementation of Python code to manipulate and analyze data structures. The test is designed to assess the understanding and application of Python programming concepts within a 60-minute timeframe.

Uploaded by

imadberbarijnr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Python Data Structures Test Worksheet

The document is a Python Data Structures Test Worksheet consisting of various sections that cover advanced operations on lists, tuples, dictionaries, and sets. Each section contains specific tasks that require the implementation of Python code to manipulate and analyze data structures. The test is designed to assess the understanding and application of Python programming concepts within a 60-minute timeframe.

Uploaded by

imadberbarijnr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Data Structures Test Worksheet

Time Allowed: 60 Minutes

Instructions:

• Answer all questions. Paste code under each question.

• Write clean and well-structured Python code.

• Add comments where necessary.

Section A – Lists (Advanced Operations)


1. List Manipulation
Create a list containing the numbers:
[15, 42, 8, 23, 16, 4, 9, 55]

Perform the following:


a) Insert 100 at index 3
b) Remove the smallest number using a list method
c) Sort the list in ascending order
d) Print the second largest number
e) Reverse the list

2. List Filtering Problem


Write a program that:
• Takes 10 numbers from the user
• Stores them in a list
• Creates two new lists:
- One containing even numbers
- One containing odd numbers
Print both lists.

3. Nested Lists
students = [
["Ali", 78],
["Sara", 92],
["Ahmed", 65],
["Zara", 88]
]
Write code to:
a) Print the name of the student with highest marks
b) Calculate the average marks
c) Add a new student ["Usman", 90]

4. Remove Duplicates (Without set)


Write a program that removes duplicate elements from the list:
[4, 7, 2, 7, 9, 2, 4, 5]
Do not use set().

Section B – Tuples
5. Tuple Operations
data = (10, 20, 30, 40, 20, 50)

a) Print the length of the tuple


b) Count how many times 20 appears
c) Find the index of 40
d) Slice the tuple from index 1 to 4

6. Tuple Unpacking
person = ("Ali", 21, "Computer Science")

Use tuple unpacking and print:


Name:
Age:
Field:

7. Tuple and List Conversion


1. Convert tuple (5, 10, 15, 20) into a list
2. Add 25 to the list
3. Convert it back into a tuple

Section C – Dictionaries
8. Student Record System
Create a dictionary with:
Name, Age, Course, Marks

Then:
a) Add a new key city
b) Update marks
c) Print all keys and values using a loop

9. Dictionary Processing
marks = {
"Alice": 85,
"Bob": 72,
"Charlie": 90,
"David": 68
}

a) Print the student with highest marks


b) Print students who scored above 80
c) Calculate the average marks

10. Character Frequency Counter


Write a program that counts the frequency of each character in:
"programming"
Use a dictionary.

11. Dictionary Comprehension


Create a dictionary where:
Keys = numbers from 1 to 6
Values = cube of the number

Section D – Sets
12. Set Operations
A = {2, 4, 6, 8, 10}
B = {4, 8, 12, 16}

Perform:
a) Union
b) Intersection
c) Difference (A - B)

13. Unique Elements


[3, 5, 7, 3, 2, 5, 9, 7]

a) Remove duplicates using set


b) Print unique elements in sorted order
14. Common Elements
list1 = [1,2,3,4,5]
list2 = [4,5,6,7,8]

Find common elements using sets.

Section E – Mixed Data Structures


15. List + Dictionary Problem
students = [
{"name": "Ali", "marks": 85},
{"name": "Sara", "marks": 92},
{"name": "Ahmed", "marks": 78}
]

a) Print the top scoring student


b) Calculate the average marks
c) Add a new student record

16. Set + List Problem


"python makes programming powerful and python makes coding fun"

a) Store unique words using a set


b) Print the number of unique words

17. Data Structure Comparison


Explain differences between:
List
Tuple
Dictionary
Set

Based on:
• Mutability
• Ordering
• Duplicate values

You might also like