Skip to content
Advertisement

Create array of values in an if statement in Python

I want to create an array of values based on a condition.

JavaScript

The output I want:

JavaScript

I mess with the loop, I don’t have the input I need. I know I have to append or populate the array.

Advertisement

Answer

As others said, you must assign model_ds list outside the loop, because having it inside the loop it gets empty with every iteration. Your code should be (line that changed is with comment):

JavaScript

Output:

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