lambda and if

Emile van Sebille emile at fenx.com
Mon Jun 12 07:07:37 EDT 2000


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
>





More information about the Python-list mailing list