Skip to content
Advertisement

How to change the for loop to list comprehension?

In the following code snippet:

JavaScript

The output is:

JavaScript

I wonder how to change the for loop to a list comprehension?

Advertisement

Answer

JavaScript

This should work, here is a basic example

JavaScript

Would instead be

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