58.0k views
0 votes
Write a Python function called print_nested_list that takes a single parameter, a list of lists of strings. Complete the function as follows: Each list of strings should be printed with a single space between each string, all on the same line Each list of strings should be printed on its own line Your code shouldn't return a value. For example, the list [["Test"], ["Example", "Online"] should print: Test Example Online

User Koenyn
by
5.1k points

1 Answer

4 votes

Answer:

def print_nested_list(lst):

for sub_list in lst:

print(*sub_list)

lst = [["Test"], ["Example", "Online"]]

print_nested_list(lst)

Step-by-step explanation:

Create a function named print_nested_list that takes one parameter, lst

Inside the function, create a for loop that iterates through the lst

Inside the for loop, print each sublist by using print(*sub_list)

(*sub_list allows us to unpack the lst so that we will be able to reach each sublist inside the lst)

Call the function to test with a nested list

User Val Blant
by
4.3k points