sort and delete ?

Michal Wallace (sabren) sabren at manifestation.com
Tue May 30 13:05:26 CEST 2000


On Tue, 30 May 2000, matt wrote:

> Hi, 
> 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)


Hmmm.. I think you mean:

> ...
> 	if i[1][1] in ('ace','three'):
> ...

which results in: x==[['egg', [1, 'ace', 3]], ['pear', [4, 'three', 6]]]


So does this:

x = filter(lambda x: x[0][1] in ("ace","three"), a)


Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------





More information about the Python-list mailing list