21.4k views
1 vote
Write a set of nested loops that display the contents of the numbers list below: numbers = [[1, 2], [10, 20], [100, 200], [1000, 2000]

1 Answer

3 votes

Final answer:

To display the contents of a nested list in Python, use a for loop to iterate over each sub-list, and another nested for loop to print out each item in the sub-lists.

Step-by-step explanation:

To display the contents of the list numbers with nested loops, you can write a simple outer loop to go through each sub-list and an inner loop to go through each element of the sub-list. The Python code snippet below demonstrates this:

numbers = [[1, 2], [10, 20], [100, 200], [1000, 2000]]
for sub_list in numbers:
for item in sub_list:
print(item)

This will print out each number in the sub-lists of the numbers list, line by line.

User Akshay Nandwana
by
8.3k points