Skip to content
Advertisement

Function returns only first element of the list

I am trying to get every element from python list returned as a string, but it returns only the first element of the list, not continuing the loop.

Main Code (prishot.py)

JavaScript

Test code to run the above (test.py)

JavaScript

After running the test.py it gives me only the first sentence in the list s in prishot.py: Screenshot of CMD

But if I try printing the index_list (which is in prishot.py) without the rest, you can clearly see, that there are 21 indexes there. Screenshot of CMD

So here is the output, I want it to be. As you can see here are all the sentences, which are stored in list s in prishot.py. When running test.py it returns only the first sentence. I need to return the rest just the same as in the first picture. All the sentences First sentence output

Advertisement

Answer

You can use yield for creating a generator

JavaScript

By adding this on test.py

JavaScript

OR,
You can try
As this outputs line by line with no change in test.py.

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