Python: Remove the first item from a specified list
Remove First List Item
Write a Python program to remove the first item from a specified list.
Sample Solution-1:
Python Code:
Sample Output:
Original list elements: ['Red', 'Black', 'Green', 'White', 'Orange'] After removing the first color: ['Black', 'Green', 'White', 'Orange']
Sample Solution-2:
Python Code:
Sample Output:
Original list elements: ['Red', 'Black', 'Green', 'White', 'Orange'] After removing the first element from the said list: ['Black', 'Green', 'White', 'Orange']
Sample Solution-3:
Python Code:
Sample Output:
Original list elements: ['Red', 'Black', 'Green', 'White', 'Orange'] After removing the first element from the said list: ['Black', 'Green', 'White', 'Orange']
Sample Solution-4:
- Use slice notation to return the last element if the list's length is more than 1.
- Otherwise, return the whole list.
Python Code:
Sample Output:
[2, 3, 4] [1] ['Black', 'Green', 'White', 'Orange']
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to remove the last item from a list.
- Write a Python program to remove an element at a given index from a list.
- Write a Python program to remove all occurrences of a specific value from a list.
- Write a Python program to remove duplicate elements from a list while preserving order.
Go to:
Previous: Write a Python program to make file lists from current directory using a wildcard.
Next: Write a Python program to input a number, if it is not a number generates an error message.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.