﻿ Python: Reverse a given list of lists - w3resource

# Python: Reverse a given list of lists

## Python List: Exercise - 150 with Solution

Write a Python program to reverse a given list of lists.

Sample Solution:

Python Code:

``````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))
```
```

Sample Output:

```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]]
```

Flowchart:

## 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.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Floor Division:

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)```

Output:

```3
3.3333333333333335```