Print all value when iterating over loop

Hi everyone,

I am writing this topics to ask you for helping me in my code
I am trying to make a simple app the iterate over a list of Id and return back the status of them

But the problem I am facing that it is only return the first result not all result

Please see the following code snippet to better understand.


ID = 1234
   for row in data.itertuples():
         if ID == row.PT_NO:
            print("Result:", row.Result)

The Output:
Result: 1
Result: 0
Result: 1


Here when I use print in Jupyter , all good and all result printed.

@anvil.server.callable

def ReturnStatusofId (ID):
     for row in data.itertuples():
         if ID == row.PT_NO:
            return ("Result", row.Result)

     return ("No Result Found")


Here when put the code inside the anvil function in jupyter.


And when i run the api in anvil, only the first one printed.

 def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    ID= self.id.text
    
    funA = anvil.server.call("ReturnStatusofId ",ID)
    if funA:
      self.result.visible = True
      self.result2.visible = True
      self.result.text = 'The Status of Patient :'
      self.result2.text =funA     

This is my function.

Can you please help me
And thank you

Hi,

In your first snippet you are printing the result if there is a match, so the for loop continues to completion.
In your second snippet you are returning the result of the first match, so the for loop exits at that point.
If you need to return a list of results that match, then you will need to build that list up incrementally and return that once the for loop has completed (or restructure the for loop into a list comprehension).

1 Like