Learn with Yasir

Share Your Feedback

Python List Exercises – Practice Questions for Beginners

Practice Python list concepts with beginner-friendly exercises. Strengthen your understanding of list creation, indexing, slicing, and manipulation with hands-on coding problems and solutions.

Topic: lists


🧪 Coding Exercises

🟢 Beginner Exercises

  1. List Creation and Indexing
  2. 1. Create a list called `fruits` with these elements: 'apple', 'banana', 'cherry', 'date'
    2. Print the first and last elements using indexing
    3. Print every alternate fruit starting from the second one
    

    Requirements

    • Use positive and negative indexing
    • Use slicing for alternate elements

    Input

    No input required

    Expected Output

    First: apple
    Last: date
    Alternate: ['banana', 'date']
    

    📚 Python Lists






🟡 Intermediate Exercises


  1. List Slicing Operations
  2. Given the list: numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    1. Create a new list with first 5 numbers
    2. Create a new list with last 3 numbers
    3. Create a new list with even-indexed numbers
    4. Create a reversed version of the list
    

    Requirements

    • Use slicing operations only
    • Don't use any loop constructs

    Input

    No input required

    Expected Output

    First 5: [0, 1, 2, 3, 4]
    Last 3: [7, 8, 9]
    Even indexed: [0, 2, 4, 6, 8]
    Reversed: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
    

    📚 Python List Slicing



  3. List Methods Practice
  4. Start with an empty list called `inventory`
    1. Add items: 'sword', 'shield', 'potion' (in this order)
    2. Insert 'helmet' at the beginning
    3. Remove 'shield' from the list
    4. Sort the items alphabetically
    5. Count how many 'potion' items exist
    

    Requirements

    • Use appropriate list methods for each operation
    • Print the list after each step

    Input

    No input required

    Expected Output

    After adding: ['sword', 'shield', 'potion']
    After inserting: ['helmet', 'sword', 'shield', 'potion']
    After removing: ['helmet', 'sword', 'potion']
    After sorting: ['helmet', 'potion', 'sword']
    Potion count: 1
    

    📚 Python List Methods




🔴 Advanced Exercises




  1. Combined List Operations
  2. Given two lists:
    list1 = [1, 2, 3, 4, 5]
    list2 = [10, 20, 30, 40, 50]
    
    1. Create a new list containing elements from both lists
    2. Replace the middle three elements (2,3,4) with [99, 100]
    3. Remove the last two elements
    4. Double each remaining element
    

    Requirements

    • Don't modify the original lists
    • Use list concatenation, slicing, and comprehension

    Input

    No input required

    Expected Output

    Final list: [2, 200, 10, 20, 30, 40, 50]
    

    📚 Python List Operations