On Wed, Apr 9, 2008 at 7:12 AM, Dinesh B Vadhia
<[EMAIL PROTECTED]> wrote:
> I want to replace the for loop with a List Comrehension (or whatever) to
> improve performance (as the data list will be >10,000].  At each stage of
> the for loop I want to print the result ie.

List comprehensions are for building lists, not consuming them.  If
you want to do something with every element in a list, other than
building a new list with it, you should be using a for loop.

> [print (item + "\n")  for item in data]
>
> But, this doesn't work as the inclusion of the print causes an invalid
> syntax error.
>
> Any thoughts?

Don't do this.

Perhaps you could share a small piece of code that you think is too
slow, and ask for advice in speeding it up?  If you're not sure which
small pieces of code are too slow, you need to profile your
application to find out.  See the documentation for python's profile
module.  If you don't have enough code written to profile, then it's
probably too early to be doing these optimizations.

-- 
Jerry
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to