Skip to content

Lists and Filtering Algorithms #13

@AlexRubio1

Description

@AlexRubio1

Lists HW Hacks

Date: Apr 9, 2025
Read Time: 2 min
CSP Big Idea 2


Popcorn Hacks

Popcorn Hack 1

A list allows for a lot of data to be stored in one place and allows for proper organization.
Some examples of lists are:

  • Music playlists
  • Shopping lists
  • Online catalogs

Popcorn Hack 2

The list would output "eraser", since it’s the second one in the index and third one in the overall list after deleting and adding a sharpener.


Popcorn Hack 3

A real world example of a filtering algorithm is online shopping when you apply filters to the website to only get items that are within your budget.


Homework Hacks

Python List and Procedures

items = ["soccer", "football", "cricket", "badminton", "softball"]

# List Procedure 1: Append - Adds a new item to the end of the list
items.append("basketball")  
# Now: ["soccer", "football", "cricket", "badminton", "softball", "basketball"]

# List Procedure 2: Remove - Removes a specific item from the list
items.remove("soccer")  
# Now: ["football", "cricket", "badminton", "softball", "basketball"]

# List Procedure 3: Insert - Inserts an item at a specific index
items.insert(3, "ballet")  
# Now: ["football", "cricket", "badminton", "ballet", "softball", "basketball"]

# Print final list to show result
print("Final List:", items)

##Output:

Final List: ['football', 'cricket', 'badminton', 'ballet', 'softball', 'basketball']


## Traversal Instructions

**Steps:**
1. Use a `for` loop to navigate through items.  
2. Traversal starts at index 0.  
3. Print each item.

for item in items:
    print("Current item:", item)

##output:
Current item: football  
Current item: cricket  
Current item: badminton  
Current item: ballet  
Current item: softball  
Current item: basketball  

## FIltering:

import pandas as pd

# Convert list to DataFrame
df = pd.DataFrame(items, columns=["Item"])

# Filter items containing the letter 'e'
filtered_df = df[df["Item"].str.contains("e")]

# Print the filtered list
print("Filtered Items (contain 'e'):")
print(filtered_df)


Final Reflection

Filtering algorithms and lists are used in real life for organizing and analyzing large amounts of data, such as:
	•	Sorting emails by unread statusRecommending movies based on preferences

They help systems quickly search and process information, which increases customer satisfaction and improves the effectiveness of algorithms and code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions