import pandas as pd
# 1) Create a list with at least five items
fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# List Procedure 1: Append - adding a new item to the list
fruits.append('fig') # Adds 'fig' to the end of the list
# List Procedure 2: Remove - removing a specific item from the list
fruits.remove('banana') # Removes 'banana' from the list
# List Procedure 3: Sort - sorting the list alphabetically
fruits.sort() # Sorts the list in alphabetical order
print("Modified fruit list:", fruits)
# 2) List Traversal
print("\nTraversing the fruit list:")
for fruit in fruits:
print(fruit) # Prints each fruit in the list, one at a time
# 3) Filtering Algorithm (using pandas)
# Condition: Filter only fruits that start with the letter 'e'
fruit_df = pd.DataFrame(fruits, columns=['Fruit'])
filtered_df = fruit_df[fruit_df['Fruit'].str.startswith('e')]
print("\nFiltered fruits (start with 'e'):")
print(filtered_df)
Filtering algorithms and lists are used in real life to process and organize large sets of data efficiently. For example, streaming services use them to recommend shows based on your viewing history by filtering content that matches your preferences.