[Tutor] omit some keys from dict

Sean 'Shaleh' Perry shalehperry@attbi.com
Thu, 07 Feb 2002 11:14:32 -0800 (PST)


On 07-Feb-2002 Remco Gerlich wrote:
> On  0, Sean 'Shaleh' Perry <shalehperry@attbi.com> wrote:
>> >>> j= {1:'hello',2:'fine',3:'python',4:'dicts',5:'lists',6:'tuples'}
>> >>> omit = [1,3,5]
>> >>> filter(lambda key, omit = omit: key not in omit, j.keys())
>> [6, 4, 2]
>> 
>> That will work even under 1.5.2.  Under 2.1 and above the 'omit = omit' can
>> be
>> left out.  If it were not for the need to place 'omit' in the scope of the
>> lambda I find the filter call much more readable.
> 
> Right, I left out the 'omit = omit' because I'm used to 2.1 code. 2.1 is
> about ten months old; 1.5.2 about three years. All my thesis code is 2.1
> style code. I expect that most newbies have downloaded Python recently. So
> I'm not posting legacy code anymore unless there's a specific reason for it.
> 

many many people are using distributions where python 1.5.2 is the only option
short of compiling it themself. Not everyone is up to that task.  I have always
been disappointed by the python community's inability to see this.  Even worse
some people are using python modules that have not been updated to 2.x and have
not had the time or ability to upgrade them.

> My personal guidelines for using filter/map/lambda:
> 

good rules of thumb.