FW: list reduction

Stephen Thorne stephen.thorne at gmail.com
Fri Mar 11 05:06:28 CET 2005


I think you mean,

newlist = [y for y in industrylist if y.cap < x]

otherwise you've got a list of caps, not a list of objects with the
cap attribute.


On Thu, 10 Mar 2005 12:10:31 -0800, James Stroud <jstroud at mbi.ucla.edu> wrote:
> newlist = [y.cap for y in industrylist if y.cap < x]
> 
> On Thursday 10 March 2005 12:00 pm, Leeds, Mark wrote:
> > I have a structure in python that I think is a list
> >
> > with elements .Cap and .Ticker
> >
> > where Cap is a float and Ticker is string.
> >
> >
> >
> > So, I reference things like
> >
> > industrylist[i].cap and industrylist[i].ticker
> >
> > and this works fine.
> >
> >
> >
> > What I want to do is reduce the list
> >
> > so that it only keeps elements of the list
> >
> > for which the cap is less than x where x is known ?
> >
> >
> >
> > I think I need to use filter and lambda but
> >
> > i've looked in the documentation
> >
> > and I haven't been able to figure out
> >
> > how to use it.
> >
> >
> >
> > Apologies if this is a bad question.
> >
> >
> >
> >                                     Thanks
> 
> --
> James Stroud, Ph.D.
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Stephen Thorne
Development Engineer, NetBoxBlue.com



More information about the Python-list mailing list