boyd.justin68
boyd.justin68 3h ago • 0 views

Data Structure Sample Code: Python Examples for High School Students

Hey there! 👋 Let's dive into the fascinating world of data structures in Python! It might sound intimidating, but it's actually super useful for organizing and working with information in your code. Think of it like organizing your room – data structures help you keep everything in its place! We'll go through some common examples and then test your knowledge with a quiz. Let's get started! 💻
💻 Computer Science & Technology

1 Answers

✅ Best Answer
User Avatar
sierra_coleman Dec 28, 2025

📚 Quick Study Guide

  • 🍎 Lists: Ordered, mutable (changeable) collections. You can add, remove, or modify elements. Example: `my_list = [1, 2, 3]`
  • 📦 Tuples: Ordered, immutable (unchangeable) collections. Once created, you cannot modify a tuple. Example: `my_tuple = (1, 2, 3)`
  • 🧮 Dictionaries: Collections of key-value pairs. Keys must be unique and immutable. Example: `my_dict = {"name": "Alice", "age": 16}`
  • 🧩 Sets: Unordered collections of unique elements. Sets are useful for removing duplicates. Example: `my_set = {1, 2, 3}`
  • ⏱️ Time Complexity: Understanding how the execution time of operations on each data structure scales with the input size. For example, accessing an element in a list by index is typically $O(1)$, while searching for an element in an unsorted list is $O(n)$.

🧪 Practice Quiz

  1. Which data structure is immutable?
    1. List
    2. Dictionary
    3. Tuple
    4. Set
  2. Which data structure uses key-value pairs?
    1. List
    2. Tuple
    3. Set
    4. Dictionary
  3. Which data structure does NOT allow duplicate elements?
    1. List
    2. Tuple
    3. Dictionary
    4. Set
  4. Which of the following is the correct way to create an empty list in Python?
    1. `my_list = {}`
    2. `my_list = ()`
    3. `my_list = []`
    4. `my_list = set()`
  5. What is the time complexity of accessing an element in a list by its index?
    1. $O(n)$
    2. $O(log n)$
    3. $O(1)$
    4. $O(n^2)$
  6. Which data structure is best suited for storing a collection of unique student IDs?
    1. List
    2. Tuple
    3. Dictionary
    4. Set
  7. What will be the output of the following code? python my_dict = {"apple": 1, "banana": 2} print(my_dict["apple"])
    1. "apple"
    2. "banana"
    3. 1
    4. 2
Click to see Answers
  1. C
  2. D
  3. D
  4. C
  5. C
  6. D
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀