Python: Reverse a given list of lists
Python List: Exercise - 150 with Solution
Write a Python program to reverse a given list of lists.
def reverse_list_of_lists(list1): return list1[::-1] colors = [['orange', 'red'], ['green', 'blue'], ['white', 'black', 'pink']] print("Original list:") print(colors) print("\nReverse said list of lists:") print(reverse_list_of_lists(colors)) nums = [[1,2,3,4], [0,2,4,5], [2,3,4,2,4]] print("\nOriginal list:") print(nums) print("\nReverse said list of lists:") print(reverse_list_of_lists(nums))
Original list: [['orange', 'red'], ['green', 'blue'], ['white', 'black', 'pink']] Reverse said list of lists: [['white', 'black', 'pink'], ['green', 'blue'], ['orange', 'red']] Original list: [[1, 2, 3, 4], [0, 2, 4, 5], [2, 3, 4, 2, 4]] Reverse said list of lists: [[2, 3, 4, 2, 4], [0, 2, 4, 5], [1, 2, 3, 4]]
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to get all possible combinations of the elements of a given list.
Next: Write a Python program to find the maximum and minimum values in a given list within specified index range.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
When we speak of division we normally mean (/) float division operator, this will give a precise result in float format with decimals.
For a rounded integer result there is (//) floor division operator in Python. Floor division will only give integer results that are round numbers.
print(1000 // 300) print(1000 / 300)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework