web service to iterate over la list returned

I have built a web service using cherry.py and am having issues on what is most likley very simple.  I have a web service call that returns a list of strings and I simply need to print this back to the browser.

I have something like this:
for item in stat:
     return (item)

It will only return the first element and then stops. How to I iterate over all the list elements??
LVL 1
andrew_89Asked:
Who is Participating?
 
clockwatcherConnect With a Mentor Commented:
Return returns.  So the first time through the loop you return.

Not sure exactly how you want to represent your list to your client but one way might be:

   return ",".join(stat)


Another way (which returns the same as the above just in a much more roundabout way):

   retval = ""
   for item in stat:
      retval += stat + ","

   return retval[:-1]


Another way (which returns your list JSONified):

   import json
   return json.dumps(stat)

0
 
clockwatcherCommented:
Sorry (typo):

   retval = ""
   for item in stat:
      retval += item + ","

   return retval[:-1]
0
 
andrew_89Author Commented:
awesome thanks, I am new to web services so this was throwing me..
0
All Courses

From novice to tech pro — start learning today.