Skip to the content.

Study Plan 5

with notes

Study Plan: Python Lists and Filtering Algorithms

Overview

This study plan covers the concepts of Lists and Filtering Algorithms in Python. The goal is to understand how lists are used in Python, how to manipulate them, and how to apply filtering algorithms effectively.


Objectives

  • Understand Python lists, their properties, and manipulation methods.
  • Master list operations (access, modify, remove, append).
  • Understand and apply filtering algorithms to extract data based on conditions.
  • Evaluate the performance of filtering algorithms in Python.

Lesson Breakdown

Lesson 1: Introduction to Lists

  • Definition: A list is an ordered, mutable collection of elements in Python. It can store multiple data types.

    • Creating a list:
      example_list = [42, 3.1415, "Python", True]
      print(example_list)
      
    • Accessing List Elements:
      • Positive indexing (starts from 0).
      • Negative indexing (starts from -1 for the last element).
      colors = ["red", "green", "blue", "yellow"]
      print(colors[2])  # Output: blue
      print(colors[-1]) # Output: yellow
      
    • Modifying Lists:
      • Change an element: colors[1] = "purple"
      • Add an element: colors.append("orange")
      • Remove an element: colors.remove("red")
      print(colors)  # Output: ['purple', 'blue', 'yellow', 'orange']
      

Popcorn Hack #1 (5 minutes)

  • Create a list movies with your four favorite movies.
  • Replace the second movie with a new one, add another movie, and display the updated list.

Lesson 2: Filtering Algorithms

  • Definition: Filtering algorithms extract elements based on specific conditions.

    • Basic Example: Filter even numbers.

      numbers = [11, 14, 18, 23, 29, 32, 40]
      even_numbers = [num for num in numbers if num % 2 == 0]
      print(even_numbers)  # Output: [14, 18, 32, 40]
      

Popcorn Hack #2 (8 minutes)

  • Given the list ages = [15, 20, 34, 16, 18, 21, 14, 19], write Python code to create a new list with ages 18 or older.

Lesson 3: Efficiency and Performance of Filtering Algorithms

  • Time Complexity: Filtering algorithms usually iterate through the entire list, resulting in O(n) time complexity, where n is the number of elements.

  • Considerations:

    • Filtering large datasets takes longer.
    • Understanding efficiency helps optimize performance in large-scale applications.

Homework Hacks

  1. Watch the Videos: Write 3 bullet points per video. If you have more than 6 bullet points, you’ll be rewarded.
  2. Create Python Code:
    • Initialize a list of numbers from 1 to 30.
    • Filter out and display numbers divisible by 3 but not by 5.
    • Print both the original and filtered lists.
  3. Develop a Function:
    • Write filter_spotify_data that reads data from a Spotify CSV and filters songs with over 10 million streams. Display the filtered data clearly.

Review Questions

  1. Explain what lists are in Python, including how to modify and manipulate them.
  2. Provide a real-world scenario where a filtering algorithm might be applied.
  3. Discuss why analyzing the efficiency of filtering algorithms is important for software development.

Submission

  • Submit detailed code implementations and answers to the review questions by 4/10 at 11:59 PM.