[Tutor] List comprehensions
pylinuxian at gmail.com
Wed Apr 9 22:01:35 CEST 2008
On Wed, Apr 9, 2008 at 7:44 PM, Jerry Hill <malaclypse2 at gmail.com> wrote:
> On Wed, Apr 9, 2008 at 7:12 AM, Dinesh B Vadhia
> <dineshbvadhia at hotmail.com> 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
> > 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.
> Tutor maillist - Tutor at python.org
if you explain the source of the list, what do you want to change in it,
what destination will it take, i m sure the guys here will help a lot.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor