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
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
No input required
First: apple
Last: date
Alternate: ['banana', 'date']
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
No input required
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]
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
No input required
After adding: ['sword', 'shield', 'potion']
After inserting: ['helmet', 'sword', 'shield', 'potion']
After removing: ['helmet', 'sword', 'potion']
After sorting: ['helmet', 'potion', 'sword']
Potion count: 1
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
No input required
Final list: [2, 200, 10, 20, 30, 40, 50]