Python List Practice: 17 Core Challenges with Solutions

Master Python lists with this curated collection of 17 structured practice challenges spanning all essential sequence operations, method behaviors, and algorithmic patterns.

Interactive Practice Problem Set: Each challenge features an interactive solution toggle, syntax-highlighted code, dedicated terminal output, and technical notes. Practice operations across append(), extend(), insert(), remove(), pop(), copy(), sort(), and clear().

Part 1: Initialization, Indexing & Slicing (Challenges 1 to 5) 🔝

  1. Challenge 1: Declare an empty list and populate it with multiple items.
    my_list = []
    my_list.append('Alex')
    my_list.append('Ronn')
    my_list.append('Geek')
    print("Populated list:", my_list)

    Terminal Output:

    Populated list: ['Alex', 'Ronn', 'Geek']
  2. Challenge 2: Mixed data types and element retrieval by index.
    mixed = ['Alex', 4, 'Ronn', 6.54]
    print("List type:      ", type(mixed))
    print("Item at index 2:", mixed[2])

    Terminal Output:

    List type:       <class 'list'>
    Item at index 2: Ronn
  3. Challenge 3: Generate a stepped list using range().
    stepped_list = list(range(5, 50, 10))
    print("Stepped list:", stepped_list)

    Terminal Output:

    Stepped list: [5, 15, 25, 35, 45]
  4. Challenge 4: Negative indexing to access trailing elements.
    nums = [10, 20, 30, 40, 50]
    print("Last item (-1):        ", nums[-1])
    print("Second-to-last (-2):   ", nums[-2])

    Terminal Output:

    Last item (-1):         50
    Second-to-last (-2):    40
  5. Challenge 5: Extract sub-slices using slice syntax [start:end].
    data = [2, 4, 1, 5, 3, 7]
    print("Slice [1:]:  ", data[1:])
    print("Slice [2:4]: ", data[2:4])

    Terminal Output:

    Slice [1:]:   [4, 1, 5, 3, 7]
    Slice [2:4]:  [1, 5]

Part 2: Mutation & Method Operations (Challenges 6 to 10) 🔝

  1. Challenge 6: Locating items with index() and testing membership with in.
    names = ["Alex", "Ronald", "John", "Sarah"]
    target = "John"
    if target in names:
        print(f"'{target}' located at index:", names.index(target))

    Terminal Output:

    'John' located at index: 2
  2. Challenge 7: Inserting at specific index vs. Appending at tail.
    queue = ["User1", "User2"]
    queue.append("User3")       # Added to end
    queue.insert(1, "VIP_User") # Inserted at index 1
    print("Updated queue:", queue)

    Terminal Output:

    Updated queue: ['User1', 'VIP_User', 'User2', 'User3']
  3. Challenge 8: Merging sequences with extend() vs. Nested append().
    base = [1, 2]
    base.extend([3, 4])
    print("After extend():", base)
    
    nested = [1, 2]
    nested.append([3, 4])
    print("After append():", nested)

    Terminal Output:

    After extend(): [1, 2, 3, 4]
    After append(): [1, 2, [3, 4]]
  4. Challenge 9: Value deletion (remove) vs. Index popping (pop).
    items = ["apple", "banana", "cherry", "date"]
    items.remove("banana")     # Deletes by matching value
    popped = items.pop(1)      # Removes and returns item at index 1
    print("Popped item:  ", popped)
    print("Remaining list:", items)

    Terminal Output:

    Popped item:   cherry
    Remaining list: ['apple', 'date']
  5. Challenge 10: Shallow cloning with copy() vs. In-place clear().
    original = ["a", "b", "c"]
    snapshot = original.copy()
    original.clear()
    
    print("Original after clear():", original)
    print("Preserved snapshot:    ", snapshot)

    Terminal Output:

    Original after clear(): []
    Preserved snapshot:     ['a', 'b', 'c']

Part 3: Counting, Sorting & Deduplication (Challenges 11 to 14) 🔝

  1. Challenge 11: Length inspection with len() and frequency counting with count().
    nums = [10, 20, 10, 30, 10, 40]
    print("Total length:", len(nums))
    print("Count of 10: ", nums.count(10))

    Terminal Output:

    Total length: 6
    Count of 10:  3
  2. Challenge 12: Sequence inversion using list.reverse() in-place.
    letters = ['a', 'b', 'c', 'd']
    letters.reverse()
    print("Inverted list:", letters)

    Terminal Output:

    Inverted list: ['d', 'c', 'b', 'a']
  3. Challenge 13: Sorting by custom key (length) in ascending and descending orders.
    words = ["Alexander", "Sam", "Christopher", "Jo"]
    words.sort(key=len)
    print("Ascending by length: ", words)
    
    words.sort(key=len, reverse=True)
    print("Descending by length:", words)

    Terminal Output:

    Ascending by length:  ['Jo', 'Sam', 'Alexander', 'Christopher']
    Descending by length: ['Christopher', 'Alexander', 'Sam', 'Jo']
  4. Challenge 14: Deduplicate items while preserving original insertion order.
    raw_tags = ["python", "spam", "tutorial", "spam", "coding"]
    # dict.fromkeys preserves order in O(N) linear time
    unique_tags = list(dict.fromkeys(raw_tags))
    print("Deduplicated tags:", unique_tags)

    Terminal Output:

    Deduplicated tags: ['python', 'spam', 'tutorial', 'coding']

Part 4: Reductions, Conversions & Set Intersections (Challenges 15 to 17) 🔝

  1. Challenge 15: Numeric aggregations: sum(), min(), and max().
    scores = [45, 12, 89, 3, 67]
    print("Sum:    ", sum(scores))
    print("Minimum:", min(scores))
    print("Maximum:", max(scores))

    Terminal Output:

    Sum:     216
    Minimum: 3
    Maximum: 89
  2. Challenge 16: Splitting strings to character lists and deduplicating.
    text = "programming"
    char_list = list(text)
    unique_chars = list(dict.fromkeys(char_list))
    print("Character list:   ", char_list)
    print("Deduplicated chars:", unique_chars)

    Terminal Output:

    Character list:    ['p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']
    Deduplicated chars: ['p', 'r', 'o', 'g', 'a', 'm', 'i', 'n']
  3. Challenge 17: Finding common elements between two lists using set intersection.
    list_a = [1, 2, 3, 4, 5]
    list_b = [3, 4, 5, 6, 7]
    common_items = sorted(list(set(list_a) & set(list_b)))
    print("Common elements:", common_items)

    Terminal Output:

    Common elements: [3, 4, 5]

Interactive Notebook & Practice Exercises 🔝

Work through all 17 challenges and self-validating assertions in our companion Jupyter Notebook:

Interactive Companion Jupyter Notebook

Explore interactive code cells for all challenges, test list slicing, benchmark methods, and run self-validating unit assertions.

View on GitHub Run in Google Colab

Frequently Asked Questions (FAQ) 🔝

How do I safely remove an item without errors?

Use if item in my_list: my_list.remove(item) or a try-except ValueError block.

What is the fastest way to deduplicate a list?

list(dict.fromkeys(my_list)) runs in O(N) time and maintains original insertion order.

Further Reading & Related Tutorials 🔝




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer