lambda and if

matt matt at virtualspectator.com
Mon Jun 12 07:20:34 EDT 2000


sneaky ... it's nice.
might be nice to extend that with
["","big"][x[1] in ("big",)]  so we can extend the 'yes' set

but extending it to using the actual match is a little more difficult,
i.e.
 x[1] in ("big","little","wide",)  where the matched item would be appended if
it existed or else a blank


thanks
matt





On Mon, 12 Jun 2000, Emile van Sebille wrote:
> You could use this:
> 
> >>> filenames = map(lambda x:x[2] + "_" + x[0] + "_" +
> ["","big"][x[1]=="big"] + ".txt" ,items)
> 
> Emile van Sebille
> emile at fenx.com
> -------------------
> 
> 
> ----- Original Message -----
> From: matt <matt at virtualspectator.com>
> To: <python-list at python.org>
> Sent: Monday, June 12, 2000 3:46 AM
> Subject: lambda and if
> 
> 
> > say you had the following
> >
> > filenames = map(lambda x:x[2] + "_" + x[0] + "_" + x[1] +
> ".txt" ,items)
> >
> > but really wanted
> > filenames = map(lambda x:x[2] + "_" + x[0] + "_" + (x[1]
> in ("big",) ? "big" :
> > "") + ".txt" ,items)
> >
> > where (x[1] in ('big',) ? "big" : "") is a pseudo
> c++_pyhton expression that I
> > want to implement .....
> >
> > i.e. the result is to append "big" to the filename being
> created if it is the
> > 2nd element of item, otherwise don't append anything.
> >
> > regards
> > Matt
> >
> > --
> > http://www.python.org/mailman/listinfo/python-list
> >
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list