Lists - Your Shopping List

A list stores multiple items in order, like [item1, item2, item3]. You can: 1) Access items by position (starts at 0!), 2) Add items with .append(), 3) Remove items with .remove(), 4) Check length with len(), 5) Sort with .sort()

# Working with lists
# Creating a shopping list
shopping_list = ["apples", "milk", "bread", "eggs"]
print("My shopping list:", shopping_list)

# Accessing items (starts at 0!)
print("First item:", shopping_list[0])    # apples
print("Third item:", shopping_list[2])    # bread

# Adding items
shopping_list.append("cheese")
print("After adding cheese:", shopping_list)

# Removing items
shopping_list.remove("bread")
print("After removing bread:", shopping_list)

# List length
print("Number of items:", len(shopping_list))

# Looping through list
print("\nI need to buy:")
for item in shopping_list:
    print("- " + item)

# Sorting
numbers = [5, 2, 8, 1, 9]
numbers.sort()
print("\nSorted numbers:", numbers)