sort and delete ?
matt
matt at virtualspectator.com
Tue May 30 07:16:41 EDT 2000
Sorry about the mistake ... was trying other things before the post. Anyway
thanks for the answer, it's perfect!!
On Tue, 30 May 2000, Mikael Olofsson wrote:
> On 30-May-00 matt wrote:
> > Is there a more "pythonic" way to do the following, which, before I make a
> > mess
> > is, suppossed to assess whether to throw elements out of a list and then
> > actually do so. I use a rather strange, but database-like, list.
> >
> > a = [['egg', [1, 'ace', 3]], ['apple', [1, 'two', 3]], ['pear', [4,
> > 'three',
> > 6]], ['orange', [5, 'two', 1]]]
> >
> > x=[]
> > for i in a:
> > if i[0][1] in ('ace','three'):
> > x.append(i)
>
> First of all, I think you meant i[1][1] above. I am an addict under the
> lambda-forms, so I would do it using filter:
>
> x = filter(lambda i:i[1][1] in ('ace','three'),a)
>
> Cheers,
>
> /Mikael
>
> -----------------------------------------------------------------------
> E-Mail: Mikael Olofsson <mikael at isy.liu.se>
> WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
> Phone: +46 - (0)13 - 28 1343
> Telefax: +46 - (0)13 - 28 1339
> Date: 30-May-00
> Time: 13:04:55
>
> This message was sent by XF-Mail.
> -----------------------------------------------------------------------
>
> --
> http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list