Skip to content
Advertisement

how to combine three lists comprehension into one using only one for loop?

I have a list in range (1 to 31).

The final list is l = [x, y, z]

You can see my code, it is work fine using three for loops:

JavaScript

The outputs is:

JavaScript

I tried to do it using only one for loop.

JavaScript

I got this error:

JavaScript

I don’t know if I can do it or not.

please help me.

Advertisement

Answer

Try –

JavaScript

Or list comprehension –

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement