Skip to content
Advertisement

Print list of lists in separate lines

I have a list of lists:

JavaScript

I want the output in the following format:

JavaScript

I have tried it the following way , but the outputs are not in the desired way:

JavaScript

Outputs:

JavaScript

While changing the print call to use end instead:

JavaScript

Outputs:

JavaScript

Any ideas?

Advertisement

Answer

Iterate through every sub-list in your original list and unpack it in the print call with *:

JavaScript

The separation is by default set to ' ' so there’s no need to explicitly provide it. This prints:

JavaScript

In your approach you were iterating for every element in every sub-list and printing that individually. By using print(*s) you unpack the list inside the print call, this essentially translates to:

JavaScript
Advertisement