Nighthawk Pages

Lists HW Hacks

HW hack

CSP Big Idea 2

Popcorn hacks

Popcorn Hacks 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, or 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.

Homwork Hacks


  1. 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 items = ["soccer", "football", "cricket", "badminton", "softball", "basketball"]

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

# List Procedure 3: Insert - Inserts an item at a specific index
items.insert(3, "ballet")  # Now items = ["football", "cricket", "badminton", "ballet", "softball", "basketball"]
# Print final list to show result
print("Final List:", items)
Final List: ['football', 'cricket', 'badminton', 'ballet', 'softball', 'basketball']
  1. Traversal Instructions
    • Use a for loop to navigate through items.
    • Traversal always starts from index 0 and moves to the end of the list.
    • Finally, print the results. Below is an example.
for item in items:
    print("Current item:", item)
Current item: football
Current item: cricket
Current item: badminton
Current item: ballet
Current item: softball
Current item: basketball
  1. 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)

Filtered Items (contain 'e'):
         Item
1     cricket
3      ballet
5  basketball
##New list with items that passed the test
new_items = ["cricket", "ballet", "basketball"]

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 status or recommending movies based on preferences. They help systems quickly search and process information which increases customer satisfaction and effectivness of alogorithms and code.

Scroll to top